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. Grace Huang 2017/1/12

    原文 Huang doesn't think of acting as pretending to be someone else.Rather,she considers it an opportu ...

  2. FATAL org.apache.hadoop.hdfs.server.datanode.DataNode: Initialization failed for Block pool <registering> (Datanode Uuid unassigned) service to controller/192.168.1.183:9000. Exiting. java.io.IOExcep

    2018-01-09 09:47:38,297 FATAL org.apache.hadoop.hdfs.server.datanode.DataNode: Initialization failed ...

  3. 激励CEO们最好的办法就是鼓励他们不要停止思考

    我们应该怎样在企业中释放出每一个人都可能内在的自我驱动力呢? 我创业十多年来,结识了很多创业家,他们中很多和我一样也试图通过学习实践找到有效管理的捷径,一个最简单的法则,最好还是比较容易的.事实上,最 ...

  4. python 基础网络编程1

    python 基础网络编程1 Source code: Lib/socketserver.py lib的主目录下有一个sockserver.py文件, 里面是python基本的网络编程模型 共有一个b ...

  5. mybatis 原理研究

    1. mybatis 是使用JDBC来实现的, 所以需要我们首先了解JDBC 的查询 ①加载JDBC驱动 ②建立并获取数据库连接 ③设置sql语句的传递参数 ④执行sql语句并获得结果 ⑤对结果进行转 ...

  6. Prim算法解决最小生成树

    一.最小生成树问题 什么是最小生成树问题?给你一个带权连通图,需要你删去一些边,使它成为一颗权值最小的树. 二.Prim算法 1)输入:输入一个带权连通图,顶点集合V,边集合E 2)初始化:Vnew= ...

  7. iview table里面 插入下拉列表组件(自定义组件)一定要加key,不加key,table开始会加载所有数据,然后再从第2页点回第一页,就会走onChange事件,混乱的逻辑,切记加:key

    iview table里面 插入下拉列表组件(自定义组件)一定要加key,不加key,table开始会加载所有数据,然后再从第2页点回第一页,就会走onChange事件,混乱的逻辑,切记加:key 关 ...

  8. Schur 三角化定理的推论

    将学习到什么 从 Schur 的酉三角化定理可以收获一批结果,在这一部分介绍重要的几个.   迹与行列式 相似矩阵具有相同的特征多项式, 从特征多项式一节中, 我们又知道,相似矩阵的迹以及行列式都是相 ...

  9. C# 队列Queue

    using System; using System.Collections.Generic; using System.Linq; namespace Queue测试 { class Program ...

  10. 51nod 1242 斐波那契数列的第N项——数学、矩阵快速幂

    普通算法肯定T了,所以怎么算呢?和矩阵有啥关系呢? 打数学符号太费时,就手写了: 所以求Fib(n)就是求矩阵  |  1  1  |n-1  第一行第一列的元素. |  1  0  | 其实学过线代 ...