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 ...
随机推荐
- QQ自动登录Demo源码(附全套WindowsApi)
在开发过程中,偶尔会有自动化操作软件的需求,便想到用句柄实现自动化的功能,记录下知识点,以作备忘. 实现流程: 获取窗口句柄,根据定位获取input,调用windowsapi模拟鼠标点击, 输入 , ...
- javascript实现引用数据类型的深拷贝和浅拷贝详解
关于引用类型值的详解,请看另一篇随笔 https://www.cnblogs.com/jinbang/p/10346584.html 深拷贝和浅拷贝,也就是引用数据类型栈和堆的知识点.深浅拷贝的原型都 ...
- LeetCode 要记得一些小trick
最近搞了几场编程比赛,面试题或者是LeetCode周赛.每次都不能做完,发现时间不够用. 看了别人的代码才知道,同样实现相同的功能,可能别人只需要用一个恰当的函数,就会比自己少些不少代码,争得了时间. ...
- Spring框架及AOP
Spring核心概念 Spring框架大约由20个功能模块组成,这些模块主分为六个部分: Core Container :基础部分,提供了IoC特性. Data Access/Integration ...
- RabbitMQ 为什么需要信道?为什么不是TCP直接通信?
交换器和队列的关系 1. 交换器是通过路由键和队列绑定在一起的,如果消息拥有的“路由键”跟队列和交换器的“路由键”匹配,那么消息就会被路由到该绑定的队列当中去 2. 也就是说,消息到队列的过程中,消息 ...
- CentOS7上安装稻壳CMS
CentOS7上安装稻壳CMS 1, 安装用途 为了给某公司建设一个小型网站,租用了一个阿里云ECS服务器,最基础的硬件配置,因此选择了CentOS7操作系统. 稻壳CMS(docCMS)源于深喉咙C ...
- Visual Studio TFS
Overview:Active Directory环境下搭建TFS(一个domain内,with Domain Controller): 1)最简单的环境(这俩拓扑是从TFSAdmin文档中截取的,从 ...
- Server 2008 R2 事件查看器实现日志分析
在 windows server 2008 R2 中,可以通过点击 "开始" -> "管理工具" -> "事件查看器" ,来打开 ...
- PostgreSQL 备忘
truncate table page_frame_mst; select setval('page_frame_mst_id_seq', 1, false): select setval('imag ...
- codeforces_304C_数学题
C. Lucky Permutation Triple time limit per test 2 seconds memory limit per test 256 megabytes input ...