Let's assume that

  • v(n) is the largest prime number, that does not exceed n;
  • u(n) is the smallest prime number strictly greater than n.

Find .

Input

The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.

Each of the following t lines of the input contains integer n (2 ≤ n ≤ 109).

Output

Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.

Examples
Input
2
2
3
Output
1/6
7/30

写写1/v(i)u(i)的前几项就能发现规律

i    2   3   4   5

v   2   3   3   5

u   3   5   5   7

如果用个f(i)表示1/v(i)u(i),那么对于一个质数x,有f(2)+f(3)+...+f(x-1)=1/2-1/x

然后在对于一个夹在两质数a,b之间的x,显然从a到x的f值都是a/b,所以就是找到n前后最近的质数,把两分式通分一下就好了

这里我是直接n往前往后Miller-Robin找第一个质数,不过sqrt(n)的暴力应该也能卡过去?

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL mul(LL x,LL n,LL MOD)
{
LL res=x*n-(LL)((long double) x*n/MOD+0.5)*MOD;
while (res<)res+=MOD;
while (res>=MOD)res-=MOD;
return res;
}
LL qpow(LL x,LL n,LL MOD)
{
x=(x%MOD+MOD)%MOD;
LL p=x,con=;
while (n)
{
if (n&)con=mul(con,p,MOD);
p=mul(p,p,MOD);
n>>=;
}
return con;
}
bool witness(LL a,LL b)
{
if (a==b)return true;
LL s=b-;
int t=;
while (!(s&))s>>=,t++;
LL x=qpow(a,s,b);
if (x==)return ;
while (t--)
{
if (x==b-)return true;
x=mul(x,x,b);
if (x==)return false;
}
return false;
}
bool isprime(LL x)
{
if (x==||x==)return false;
static int p[]={,,,,,,,,,,};
for (int i=;i<=;i++)
if (!witness(p[i],x))return false;
return true;
}
inline LL gcd(LL a,LL b)
{
if (a<b)swap(a,b);
return b==?a:gcd(b,a%b);
}
int main()
{
int T=read();
while (T--)
{
LL x=read(),y,z,t,ans1,ans2;
for (y=x;y>=;y--)if (isprime(y))break;
for (z=x+;z<=1e9+;z++)if (isprime(z))break;
//ans=1/2-1/y+(x-y+1)*y/z
ans1=y*z-*z+*x-*y+;ans2=*y*z;
t=gcd(ans1,ans2);ans1/=t;ans2/=t;
printf("%lld/%lld\n",ans1,ans2);
}
}

cf396B

cf396B On Sum of Fractions的更多相关文章

  1. Codeforces Round #232 (Div. 2) D. On Sum of Fractions

    D. On Sum of Fractions Let's assume that v(n) is the largest prime number, that does not exceed n; u ...

  2. Codeforces 396B On Sum of Fractions 数论

    题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...

  3. cf D. On Sum of Fractions

    http://codeforces.com/problemset/problem/397/D 题意:v(n) 表示小于等于n的最大素数,u(n)表示比n的大的第一个素数,然后求出: 思路:把分数拆分成 ...

  4. 数学题--On Sum of Fractions

    题目链接 题目意思: 定义v(n)是不超过n的最大素数, u(n)是大于n的最小素数. 以分数形式"p/q"输出 sigma(i = 2 to n) (1 / (v(i)*u(i) ...

  5. Codeforces Round #232 (Div. 2) On Sum of Fractions

    Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest pri ...

  6. Codeforces Round #232 (Div. 1)

    这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...

  7. WannaflyUnion每日一题

    ---恢复内容开始--- 1. http://www.spoj.com/problems/KAOS/ 题意:给定n个字符串,统计字符串(s1, s2)的对数,使得s1的字典序比s2的字典序要大,s1反 ...

  8. Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)

    传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...

  9. 模拟 --- hdu 12878 : Fun With Fractions

    Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...

随机推荐

  1. 第14周翻译:SQL Server的阶梯安全级别2

    SQL Server的阶梯安全级别2:身份验证 源自:http://www.sqlservercentral.com/articles/Stairway+Series/109975/ 作者:Don K ...

  2. URAL 1519 Formula 1 (插头DP,常规)

    题意:给一个n*m的矩阵,格子中是'*'则是障碍格子,不允许进入,其他格子都是必走的格子,所走格子形成一条哈密顿回路,问有多少种走法? 思路: 本来是很基础的题,顿时不知道进入了哪个坑.这篇插头DP的 ...

  3. 一、submit和button区别

    一.submit和button区别 一.HTTP方法:GET.POST

  4. 用cssText批量修改样式

    一般情况下我们用js设置元素对象的样式会使用这样的形式: var element= document.getElementById(“id”);element.style.width=”20px”;e ...

  5. 利用python实现整数转换为任意进制字符串

    假设你想将一个整数转换为一个二进制和十六进制字符串.例如,将整数 10 转换为十进制字符串表示为 10 ,或将其字符串表示为二进制 1010 . 实现 以 2 到 16 之间的任何基数为参数: def ...

  6. Mysql插入中文时提示:ERROR 1366 (HY000): Incorrect string value: '\xE5\x8F\xB0\xE5\xBC\x8F...' fo

    Mysql插入数据时提示:ERROR 1366 (HY000): Incorrect string value: ‘\xE5\x8F\xB0\xE5\xBC\x8F…’ fo 分析如下: 首先通过语句 ...

  7. Ibatis入门基本语法

    1.       Ibatis是开源软件组织Apache推出的一种轻量级的对象关系映射(ORM)框架,和Hibernate.Toplink等在java编程的对象持久化方面深受开发人员欢迎. 对象关系映 ...

  8. 开发工具IDEA环境安装配置

    开发工具IDEA环境安装配置 该工具和eclipse类似,但是使用感受确实比eclipse好,越来越多人开始使用IDEA了. 下载地址如下 : https://www.jetbrains.com/id ...

  9. 【贪心】bzoj1572: [Usaco2009 Open]工作安排Job

    先是没怎么理解这个贪心……然后贪心又被细节弄挂…… Description Farmer John 有太多的工作要做啊!!!!!!!!为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间. ...

  10. linux运维中常用的指令

    一.终端中常用的快捷键 man界面中的快捷键: ?keyword                 向上搜索关键词keyword,n向下搜索,N继续向上搜索 /keyword   向下搜索关键词keyw ...