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 ... 
随机推荐
- Windows 下OpenSSL 安装
			安装环境: .操作系统:Windows XP SP2 2.C++编译器:VC++ 6.0 下载: 下载ActivePerl 5.10.1.1007(最新的版本或较低的版本也可以): 下载地址:htt ... 
- 【POJ3182】The Grove BFS 最短路径周围
			意甲冠军:给定一个N*M图.,间'X'代表树木(树木必须汇集到森林,非分离),然后,'.'它代表的空间.'*'它代表的起点.现在它需要从起点.一圈,最后回到起点,所经过最少点数. 题目中给的'+'就是 ... 
- hibernate批量删除和更新数据
			转载自:http://blog.csdn.net/yuhua3272004/article/details/2909538 Hibernate3.0 採用新的基于ANTLR的HQL/SQL查询翻译器, ... 
- UVA10972 - RevolC FaeLoN(双连通分量)
			题目链接 题意: 给定一个无向图,问最少加入多少条边,使得这个图成为连通图 思路:首先注意题目给出的无向图可能是非连通的,即存在孤立点.处理孤立点之后.其它就能够当作连通块来处理.事实上跟POJ335 ... 
- Linux 常用命令使用方法大搜刮(转)
			1.# 表示权限用户(如:root),$ 表示普通用户 开机提示:Login:输入用户名 password:输入口令 用户是系统注册用户成功登陆后,可以进入相应的用户环境. 退出当前shel ... 
- 利用systemtap学习Linux路由代码
			http://bbs.chinaunix.net/thread-4090162-1-1.html 一.为什么要这样做读kernel route子系统代码,当我弄懂了数据结构之间的关系以及控制流程后,心 ... 
- 使用systemtap调试linux内核
			http://blog.csdn.net/heli007/article/details/7187748 http://linux.chinaunix.net/docs/2006-12-15/3479 ... 
- Java语言基础(三)
			Java语言基础(三) 一. 补码 (1).之所以有补码是因为要考虑成本 就是造计算机的成本 (2).下面让我们分析一下补码 以四位补码为例 <1> 高位是符号位,它决定其是正数还是 ... 
- (转)if语句优化
			一.使用常见的三元操作符 if (foo) bar(); else baz(); ==> foo?bar():baz(); if (!foo) bar(); else baz(); ==> ... 
- 内网映射到公网工具 --- ngrok
			ngrok可以将内网映射到公网上,这样就可以在公网上访问你的网络服务. 该工具通常在进行app开发和微信开发时比较有用,这样就可避免在公网服务器上单独部署项目,通过映射,直接连接本地服务即可进行开发. ... 
