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. springMVC中jackson的使用(包含JsonFormat 时间格式)

    前台使用ajax,后台 springMVC Java下常见的Json类库有Gson.JSON-lib和Jackson等,Jackson相对来说比较高效,在项目中主要使用Jackson进行JSON和Ja ...

  2. SqlDbx远程链接DB2数据库

    1.首先下载IBM的IBM Data Server Client,百度云链接:http://pan.baidu.com/s/1kVBVjan 密码:2gtz 2.安装好客户端之后,打开cmd,运行db ...

  3. PG extract 函数示例

    pg 对时间的处理还是很灵活的, + - * /  都有支持 期间有个extract 函数还是很有用的,我们先来看看几个例子:[code] postgres=# select extract(epoc ...

  4. Alpha-beta pruning

    function alphabeta(node, depth, α, β, maximizingPlayer) or node is a terminal node return the heuris ...

  5. 允许Java App(applet)粘贴方法

    修改安全策略文件: "java.policy" JRE6的路径在:"C:\Program Files (x86)\Java\jre6\lib\security" ...

  6. UVA 10735 Euler Circuit (最大流)

    题意:求混合图的欧拉路径. 一句话总结:网络流,最主要在于建图,此题是将出度则是和流量联系在了一起,用最大流来调整边的指向. 分析: 这题的困难之处在于无向边只能用一次,相当于一个方向未定的有向边. ...

  7. 51nod 算法马拉松17 解题报告 以后不能赛中写题解(查逐梦者抄袭本人代码...

    B题(数学题: 问(1+sqrt(2)) ^n  能否分解成 sqrt(m) +sqrt(m-1)的形式  如果可以 输出 m%1e9+7 否则 输出no n<=1e18 刚看题没思路 暴力一下 ...

  8. Mysql闪回工具之binlog2sql的原理及其使用

    生产上误删数据.误改数据的现象也是时常发生的现象,作为运维这时候就需要出来补锅了,最开始的做法是恢复备份,然后从中找到需要的数据再进行修复,但是这个时间太长了,对于大表少数数据的修复来讲,动作太大,成 ...

  9. Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi

    http://codeforces.com/contest/476/problem/B B. Dreamoon and WiFi time limit per test 1 second memory ...

  10. css3中animation属性animation-timing-function知识点以及其属性值steps()

    在animation中最重要的其实就是时间函数(animation-timing-function)这个属性,他决定了你的动画将以什么样的速度执行,所以最关键的属性值也就是cubic-bezier(n ...