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 prime number strictly greater than n.
Find
.
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).
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.
2
2
3
1/6
7/30
分析:把公式分解1/(p*q)=1/(p-q) * (1/q-1/p) 然后求和发现公式:ans=(-2q+2*n-2*p+2+2*q*q)/(2*u*v);
1 #include<cstdio>
2 #include<cmath>
3 #include<algorithm>
4 using namespace std;
5 bool isprime(unsigned long long x)
6 {
7 int idx=sqrt(x);
8 for(int i=; i<=idx; ++i)
9 if(x%i==)
return false;
return true;
}
int main()
{
int t;
unsigned long long n;
scanf("%d",&t);
while(t--)
{
scanf("%I64u",&n);
unsigned long long v=n,u=n+;
while(!isprime(v))
--v;
while(!isprime(u))
++u;
unsigned long long p=v*u-*u+*n-*v+,q=*v*u,tmp=__gcd(p,q);
printf("%I64u/%I64u\n",p/tmp,q/tmp);
}
}
Codeforces Round #232 (Div. 2) On Sum of Fractions的更多相关文章
- 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 ...
- Codeforces Round #232 (Div. 1)
这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...
- Codeforces Round #530 (Div. 2):D. Sum in the tree (题解)
D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结 ...
- Codeforces Round #232 (Div. 2) B. On Corruption and Numbers
题目:http://codeforces.com/contest/397/problem/B 题意:给一个n ,求能不能在[l, r]的区间内的数字相加得到, 数字可多次重复.. 比赛的时候没有想出来 ...
- Codeforces Round #232 (Div. 1) A 解题报告
A. On Number of Decompositions into Multipliers 题目连接:http://codeforces.com/contest/396/problem/A 大意: ...
- Codeforces Round #599 (Div. 2) E. Sum Balance
这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <ios ...
- Codeforces Round #599 (Div. 1) C. Sum Balance 图论 dp
C. Sum Balance Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to ...
- Codeforces Round #530 (Div. 2) D. Sum in the tree 树上贪心
D. Sum in the tree 题意 给出一颗树,奇数层数的点有值,值代表从1到该点的简单路的权值的和,偶数层数的点权值被擦去了 问所有节点的和的最小可能是多少 思路 对于每一个-1(也就是值未 ...
- Codeforces Round #530 (Div. 1) 1098A Sum in the tree
A. Sum in the tree Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root ha ...
随机推荐
- bzoj 1630: [Usaco2007 Demo]Ant Counting【dp】
满脑子组合数学,根本没想到dp 设f[i][j]为前i只蚂蚁,选出j只的方案数,初始状态为f[0][0]=1 转移为 \[ f[i][j]=\sum_{k=0}^{a[i]}f[i-1][j-k] \ ...
- centos 安装sysbench
安装sysbench 下载并且解压 shell> wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbe ...
- codechef: BINARY, Binary Movements
非常有毛病的一道题,我一个一个读字符死活过不去,改成整行整行读就 A 了... 做法就是...最小点覆盖... 我们发现可以把一个点向上跳看做被吃掉了,然后最顶层的点是无法向上跳所以不能被吃掉,然后被 ...
- c++病毒函数
FreeConsole(); 屏蔽输出. BlockInput(); 阻止键盘和鼠标的工作. 所需头文件: #include <windows.h> #include <Winabl ...
- random模块思维导图
- 用Martini、websocket实现单机版聊天室
ChatRoom A stand-alone ChatRoom in Martini Please Star https://github.com/renleimlj/ChatRoom Interfa ...
- LN : leetcode 207 Course Schedule
lc 207 Course Schedule 207 Course Schedule There are a total of n courses you have to take, labeled ...
- [ NOI 2001 ] 方程的解数
\(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...
- Git——github高级
分支管理 分支不是越多越好,只求一个稳定的分支,即master不要轻易去更改 对应master要有一个开发者分支,保证mater分支的稳定性 所有的功能都在开发者分支上进行 在所有功能开发后新建发布分 ...
- JMeter在linux上分布式压测环境配置(一)
环境配置 一.在Linux服务器先安装SDK 1.先从官网下载jdk1.8.0_131.tar.gz,l(linux版本,32位,64位根据系统来判断) 2.在/usr/目录下创建java文件夹,(当 ...