Codeforces Round #232 (Div. 2) On Sum of Fractions
2024-08-31 14:08:50
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
分析:把公式分解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);
}
}
最新文章
- 分享“12306 P2P平台”创业Idea
- JS实现常用排序算法—经典的轮子值得再造
- 弱省互测#0 t1
- Max批量导出工具
- 二 J2EE 概述
- py继续
- 在VS中快速查看文件被谁签出
- Deep Learning and Shallow Learning
- [转]LoadRunner脚本录制常见问题整理
- 独木舟上的旅行--nyoj题目71
- HDU 1018-Big Number(数学)
- Android系统APN配置具体解释
- SQL Profile (总结4)--使用演示示例
- CodeForces 662D International Olympiad
- 新入门的小白,整理一下特别简单实用的div+css兼容性的问题。
- x&;(x-1)
- 10个用于处理日期和时间的 Python 库
- mysql免安装版的下载与安装
- MongoDB高可用集群+MMS集群监控搭建
- 选择排序Java版