Skip to content

396B

Solution

#include <cstdio>
using namespace std;

#define LL long long

int n;

LL gcd(LL a,LL b){
    if (a==0) return 1;
    if (a<0) return gcd(-a,b);
    while (b){
    LL t=a%b; a=b; b=t;
    }
    return a;
}

bool is_prime(int a)
{
    for (int i = 2; i * i <= a; i++)
    {
        if (a % i == 0)
            return false;
    }
    return true;
}

int main()
{
    //input
    int t;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        if (n == 2)
        {
            puts("1/6");
            continue;
        }
        int left = n;
        while (!is_prime(left))
            left--;
        int right = n + 1;
        while (!is_prime(right))
            right++;
        LL up = 1LL * (left - 2) * right + 2LL * (n - left + 1);
        LL down = 2LL * left * right;
        LL g = gcd(up, down);
        up /= g;
        down /= g;
        printf("%lld/%lld\n", up, down);
    }
    return 0;
}