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. Angular2 CLI 快速开发

    Angular2 CLI 快速开发 http://www.tuicool.com/articles/z6V3Ubz 解决npm 的 shasum check failed for错误(npm注册国内镜 ...

  2. linux用户和用户组的基本操作

    1.用户组操作 -创建用户组 # groupadd 组名 说明:新创建的组id默认从500开始,也可以通过[-g]选项指定组id,指定组id后新创建的组id会从指定的id后依次创建. -删除用户组 # ...

  3. python未知网卡名情况下获取本机IP

    import socket def get_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: # doesn't even ...

  4. 【转载】让你的MATLAB代码飞起来

    原文地址:http://developer.51cto.com/art/201104/255128_all.htm MATLAB语言是一种被称为是"演算纸"式的语言,因此追求的是方 ...

  5. OkHttp和Volley对比

    OkHttp 物理质量 使用OkHttp需要 okio.jar (80k), okhttp.jar(330k)这2个jar包,总大小差不多400k,加上自己的封装,差不多得410k. 功能介绍 Squ ...

  6. Java Concurrent之 AbstractQueuedSynchronizer

    ReentrantLock/CountDownLatch/Semaphore/FutureTask/ThreadPoolExecutor的源码中都会包含一个静态的内部类Sync,它继承了Abstrac ...

  7. C# 多线程详解 Part.04(Lock、Monitor、生产与消费)

           系列1 曾经说过:每个线程都有自己的资源,但代码区是共享的,即每个线程都可以执行相同的函数.        这可能带来的问题就是多个线程同时执行一个函数,并修改同一变量值,这将导致数据的 ...

  8. php 一些经常用到的方法

    获取当前url地址 /** * 获取当前url * @author Red * @date * @return string */ function getRequestURL() { if (!is ...

  9. 转载: 查看HADOOP中一个文件有多少块组成及所在机器ip

    看文件信息 hadoop fsck /user/filename 更详细的 hadoop fsck /user/filename -files  -blocks -locations -racks   ...

  10. 分析案例:界面提示“基础链接已经关闭:接收时发生错误”----本质为StackOverflow

    问题描述: 一个业务复杂.执行时间很长的功能,经常报出“基础链接已经关闭:接收时发生错误”,很是蹊跷... 问题分析: 首先,查阅应用服务器的系统日志,发现问题发生时总是会伴随着w3wp进程崩溃的错误 ...