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 ...
随机推荐
- js 解析 bytearray 成 字符串
function bin2String(array) { return String.fromCharCode.apply(String, array); } var bit=[104,101,108 ...
- Netty源代码学习——Included transports(变速箱)
Transport API核心: Channel介面 类图表示Channel含有Pipeline和Config接口,pipeline上一节有所介绍. Channel是线程安全的,这表示在多线环境下操作 ...
- JS为Select下拉框添加输入功能
JavaScript使用parentNode.nextSibling.value实现的本功能,实际上你会发现网页上有两个控件元素,一个是Select,一个是input,使用CSS将input覆盖于se ...
- MySQL 的 read_buffer_size 参数是如何影响写缓冲和写性能的?
Each thread // that does a sequential scan . The value of this variable should be a multiple of 4KB. ...
- innodb结构解析工具---innodb_ruby
1.下载ruby并安装ruby: ftp://ftp.ruby-lang.org/pub/ruby/ ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.3-stable. ...
- iOS-UICollectionView自定义布局
UICollectionView自定义布局 转载: http://answerhuang.duapp.com/index.php/2013/11/20/custom_collection_view_l ...
- [转] npm 模块安装机制简介
npm 是 Node 的模块管理器,功能极其强大.它是 Node 获得成功的重要原因之一. 正因为有了npm,我们只要一行命令,就能安装别人写好的模块 . $ npm install 本文介绍 npm ...
- 隐藏iframe边框
关于iframe在ie浏览器中边框隐藏的问题,一直困惑着我.其实就是一个很简单的办法,主要设置一个属性即可解决,方法如下: <iframe frameborder="0"&g ...
- Thread Runnable 多线程
1. 实现多线程的两种方法 a) 让这个类继承java.lang.Thread,然后重写run方法 b) 让这个类实现 java.lang.Runnable接口,实现r ...
- AndroidStudio工程文件导入Jar包和So第三方库
AndroidStudio 导入Jar包和第三方So库 在android开发中,需要导入许多第三方的jar包和so库来支持,包括像许多第三方的支持平台--友盟,环信.融云.极光推送.微博.腾讯等第三方 ...