D. 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 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.

Sample test(s)
input
2
2
3
output
1/6
7/30
typedef long long LL ;

bool  is_prime(LL x){
for(LL i = 2 ; i * i <= x ; i++)
if(x % i == 0)
return 0 ;
return 1 ;
} LL V(LL x){
while(! is_prime(x))
x-- ;
return x ;
} LL U(LL x){
x++ ;
while(! is_prime(x))
x++ ;
return x ;
} LL gcd(LL x , LL y){
return y == 0 ? x : gcd(y , x % y) ;
} class Node{
public :
LL zi ;
LL mu ;
public :
Node(){} ;
Node(LL z , LL m){
LL g = gcd(z , m) ;
zi = z/g ;
mu = m/g ;
} ;
Node operator + (const Node &other){
LL m , z , g ;
g = gcd(mu , other.mu) ;
m = mu / g * other.mu ;
z = other.mu / g * zi + mu /g * other.zi ;
g = gcd(z, m) ;
return Node(z/g , m/g) ;
}
Node operator - (const Node &other){
LL m , z , g ;
g = gcd(mu , other.mu) ;
m = mu / g * other.mu ;
z = other.mu /g * zi - mu / g * other.zi ;
g = gcd(z, m) ;
return Node(z/g , m/g) ;
} Node & operator = (const Node &now){
this->mu = now.mu ;
this->zi = now.zi ;
return *this ;
}
friend ostream & operator << (ostream &out , const Node &A){
out<<A.zi<<"/"<<A.mu ;
return out ;
}
}; int main(){
int t ;
LL x ;
cin>>t ;
while(t--){
cin>>x ;
LL v = V(x) ;
LL u = U(x) ;
Node ans = Node(1 , 2) - Node(1 , v) ;
Node sum = Node(x-v+1, u*v) + ans ;
cout<<sum<<endl ;
}
return 0;
}

  

Codeforces Round #232 (Div. 2) D. On Sum of Fractions的更多相关文章

  1. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  2. Codeforces Round #232 (Div. 1)

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

  3. 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 ...

  4. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  5. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  6. Codeforces Round #238 (Div. 2) D. Toy Sum(想法题)

     传送门 Description Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to s ...

  7. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  8. Codeforces Round #232 (Div. 2) B. On Corruption and Numbers

    题目:http://codeforces.com/contest/397/problem/B 题意:给一个n ,求能不能在[l, r]的区间内的数字相加得到, 数字可多次重复.. 比赛的时候没有想出来 ...

  9. Codeforces Round #232 (Div. 1) A 解题报告

    A. On Number of Decompositions into Multipliers 题目连接:http://codeforces.com/contest/396/problem/A 大意: ...

随机推荐

  1. 机械表小案例之transform的应用

    这个小案例主要是对transform的应用. 时钟的3个表针分别是3个png图片,通过setInterval来让图片转动.时,分,秒的转动角度分别是30,6,6度. 首先,通过new Date函数获取 ...

  2. Oracle数据库导入导出命令总结

    Oracle数据导入导出imp/exp就相当于oracle数据还原与备份.exp命令可以把数据从远程数据库服务器导出到本地的dmp文件,imp命令可以把dmp文件从本地导入到远处的数据库服务器中.利用 ...

  3. nohup使用(转)

    在启动weblogic的时候我们经常看到如下的命令: nohup ./startWebLogic.sh >out.log 2>&1 & 其中 0.1.2分别代表如下含义:  ...

  4. [BCB] C++ BUILDER 绘图 随机生成图形

    由于老师要求要实现一个填充算法,而每次填充都需要一个源图形[不规则],用mspaint自己画太麻烦,于是打算自己动手随机生成. 这里用的是 Polygen()函数,但是注意首尾相接,另外,为了保证规则 ...

  5. Android 中算法问题

    1:冒泡排序: 冒泡排序的思路: 相邻的两个数进行比较 (1):首先需要连个for 循环 (2):最外层for 循环控制最里面 for 循环的循环次数 (3):通过设置中间参数的方式进行交换 (4): ...

  6. sublime Text 2 配置以及 Python环境搭建

    在搭建Python环境前,先设置好Sublime Text 2的环境. 一.Sublime Text 2配置: 1.离线安装: Perferences-->Browser Packages -- ...

  7. CSS定位类型

    在CSS里面布局是相当重要的,二在这一周了,学习了一些定位,很少用到,用了更好的方式浮动.BFC.IFC等去解决问题. 而也我也对定位的概念不那么熟练运用. 初步的定位类型 1.静态定位(static ...

  8. Definition of success-成功的定义

    "My definition of success is doing what you love. I fell many people do things because they fee ...

  9. selenium环境搭建

    开发环境: 1.jdk 2.eclipse 3.selenium,selenium只需要selenium-java-2.45.jar这个就可以 具体搭建步骤可参考:http://www.cnblogs ...

  10. Visual studio智能感知挡住了当前代码输入行

    AssistX->Listboxes->Enable Visual Assist completion, suggestion and member list in .. 如果勾选了该项就 ...