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 ...
随机推荐
- php判断http头还是https头
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HT ...
- DEPENDENT SUBQUERY” 和 “SUBQUERY”
http://blog.163.com/li_hx/blog/static/183991413201642410122327/ mysql> CREATE TABLE t1 (a INT, b ...
- mysql默认用户名和密码
默认用户名:root 密码:gree..
- Android Studio安装及首次运行遇到的问题
Android Studio,下载地址:http://developer.android.com/sdk/index.html.需要注意的是Android Studio需要JDK 1.7+才可以安装, ...
- 全国OA系统下载地址(全)
思道OAhttp://www.anyoffice.net微软.NET平台,支持64位 金和OAhttp://www.jinher.com 红帆OAhttp://www.ioffice.cn 致远OAh ...
- ASP+MYSQL的配置及乱码解决
TempStr = "driver={MySQL ODBC 3.51 Driver};database="&strDB&";server="&a ...
- javaScript 的option触发事件
先说jquery的option触发事件,很方便 $("option:selected")//这样就能直接触发选择的option了 在JavaScript中就显得比较麻烦,其实< ...
- Oracle数据库之rownum
1. 介绍 当我们在做查询时,经常会遇到如查询限定行数或分页查询的需求,MySQL中可以使用LIMIT子句完成,在MSSQL中可以使用TOP子句完成,那么在Oracle中,我们如何实现呢? Oracl ...
- prototype/constructor/__proto__之prototype简单应用
一.简单使用构造原型加prototype造简单的轮子. 1.想jQ那样获取HTML元素,先看JS代码 function Cmf() { //创建构造函数 this.arry = [] } Cmf.pr ...
- 使用Thinkphp框架开发移动端接口
本文给大家分享的是使用thinkphp框架开发移动端接口的2种方法,一种是开发API,另外一种是实现移动端访问自动切换移动主题模板,从而实现伪app访问,下面我们就来详细看下如何实现吧. 方案一:给 ...