cf D. On Sum of Fractions
http://codeforces.com/problemset/problem/397/D
题意:v(n) 表示小于等于n的最大素数,u(n)表示比n的大的第一个素数,然后求出
;
思路:把分数拆分成两个分数相减,你就会发现规律,等于1/2-1/3+1/3-1/5.。。。。。。。,找出v(n)和u(n),答案就出来了。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std; int t;
ll n; ll gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
} int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
ll l,r;
bool flag=true;
for(int i=; i*i<=n; i++)
{
if(n%i==)
{
flag=false;
break;
}
}
if(flag)
{
r=n+;
while(r)
{
int f1=;
for(int i=; i*i<=r; i++)
{
if(r%i==)
{
f1=;
break;
}
}
if(f1)
{
break;
}
r++;
}
ll cc=*n*r;
ll xx=n*r-*(r-);
ll g=gcd(xx,cc);
printf("%lld/%lld\n",xx/g,cc/g);
}
else
{
l=n-;
while(l)
{
int f2=;
for(int i=; i*i<=l; i++)
{
if(l%i==)
{
f2=;
break;
}
}
if(f2)
{
break;
}
l--;
}
r=n+;
while(r)
{
int f3=;
for(int i=; i*i<=r; i++)
{
if(r%i==)
{
f3=;
break;
}
}
if(f3)
{
break;
}
r++; }
ll c1=*l*r;
ll x1=l*r-*(l+r-n-);
ll gg=gcd(x1,c1);
printf("%lld/%lld\n",x1/gg,c1/gg);
}
}
return ;
}
cf D. 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 396B On Sum of Fractions 数论
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...
- CF 964C Alternating Sum
给定两正整数 $a, b$ .给定序列 $s_0, s_1, \dots, s_n,s_i$ 等于 $1$ 或 $-1$,并且已知 $s$ 是周期为 $k$ 的序列并且 $k\mid (n+1)$,输 ...
- CF 577B Modulo Sum
题意:给一个长度为n的正整数序列,问能不能找到一个不连续的子序列的和可以被m整除. 解法:抽屉原理+dp.首先当m<n时一定是有答案的,因为根据抽屉原理,当得到这个序列的n个前缀和%m时,一定会 ...
- CF 622F The Sum of the k-th Powers——拉格朗日插值
题目:http://codeforces.com/problemset/problem/622/F 发现 sigma(i=1~n) i 是一个二次的多项式( (1+n)*n/2 ),sigma(i=1 ...
- CF 914 G Sum the Fibonacci —— 子集卷积,FWT
题目:http://codeforces.com/contest/914/problem/G 其实就是把各种都用子集卷积和FWT卷起来算即可: 注意乘 Fibonacci 数组的位置: 子集卷积时不能 ...
- 数学题--On Sum of Fractions
题目链接 题目意思: 定义v(n)是不超过n的最大素数, u(n)是大于n的最小素数. 以分数形式"p/q"输出 sigma(i = 2 to n) (1 / (v(i)*u(i) ...
- cf396B 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 ...
- 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 ...
随机推荐
- delphi TColorDialog
TColorDialog 预览 实现过程 动态创建和使用颜色对话框 function ShowColorDlg:TColor;begin with TColorDialog.Cre ...
- Qt绘图之QGraphicsScene QGraphicsView QGraphicsItem详解
Graphics View提供了一个界面,它既可以管理大数量的定制2D graphical items,又可与它们交互,有一个view widget可以把这些项绘制出来,并支持旋转与缩放.这个柜架也包 ...
- Android之提交数据到服务端方法简单封装
在Android应用中,除了单机版的应用,其余的应用免不了需要频繁地与服务端进行数据交互,如果每一种方法都独立写一段代码,那会造成代码大量重复,冗余,这不是我们所希望的,所以我们可以对其进行一些封装, ...
- vim备注
① 用户path生效 在~/.bashrc中修改path,在~/.profile中source bashrc ② secureCRT着色方案 底色RGB:43 43 43 前景色RGB:221 221 ...
- java_设计模式_外观模式_Facade Pattern(2016-08-09)
外观模式/门面模式 1.概念 为子系统中的一组接口提供一个统一接口.Facade模式定义了一个高层接口,这个接口使得这子系统更容易使用. 2.UML 由于外观模式的结构图过于抽象,因此把它稍稍具体点. ...
- ccf集合竞价
我不懂为什么是错误.然后零分.贴出测试. 然后即使注释掉while循环中的break部分,也是如此. #include<iostream> #include<iomanip> ...
- c语言字符数组和指针的经典用法
1.字符数组 许多情况下,对字符串的处理使用字符数组会更加方便,比如: 我觉得不改变字符串的原有顺序,对字符串进行删除等操作时,使用字符数组效果会更好. eg:给定字符串(ASCII码0-255)数组 ...
- 【POJ2985】【Treap + 并查集】The k-th Largest Group
Description Newman likes playing with cats. He possesses lots of cats in his home. Because the numbe ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- php开发利器
phpstorm 当前版本2016.1 之前用的为Zend studio,比之notepad++确实方便很多,不过很多方面还是不方便的,比如定位文件,上传下载到svn什么的. 看到phpstorm新版 ...