cf D. On Sum of Fractions

时间:2023-02-13 23:27:27

http://codeforces.com/problemset/problem/397/D

题意:v(n) 表示小于等于n的最大素数,u(n)表示比n的大的第一个素数,然后求出cf D. On Sum of Fractions

思路:把分数拆分成两个分数相减,你就会发现规律,等于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的更多相关文章

  1. Codeforces Round &num;232 &lpar;Div&period; 2&rpar; D&period; 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 ...

  2. Codeforces 396B On Sum of Fractions 数论

    题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...

  3. CF 964C Alternating Sum

    给定两正整数 $a, b$ .给定序列 $s_0, s_1, \dots, s_n,s_i$ 等于 $1$ 或 $-1$,并且已知 $s$ 是周期为 $k$ 的序列并且 $k\mid (n+1)$,输 ...

  4. CF 577B Modulo Sum

    题意:给一个长度为n的正整数序列,问能不能找到一个不连续的子序列的和可以被m整除. 解法:抽屉原理+dp.首先当m<n时一定是有答案的,因为根据抽屉原理,当得到这个序列的n个前缀和%m时,一定会 ...

  5. 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 ...

  6. CF 914 G Sum the Fibonacci —— 子集卷积,FWT

    题目:http://codeforces.com/contest/914/problem/G 其实就是把各种都用子集卷积和FWT卷起来算即可: 注意乘 Fibonacci 数组的位置: 子集卷积时不能 ...

  7. 数学题--On Sum of Fractions

    题目链接 题目意思: 定义v(n)是不超过n的最大素数, u(n)是大于n的最小素数. 以分数形式"p/q"输出 sigma(i = 2 to n) (1 / (v(i)*u(i) ...

  8. 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 ...

  9. Codeforces Round &num;232 &lpar;Div&period; 2&rpar; 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 ...

随机推荐

  1. Javascript常用正则表达式汇总

    一.匹配数字和字符串 整数或者小数:^[0-9]+\.{0,1}[0-9]{0,2}$ 只能输入数字:"^[0-9]*$". 只能输入n位的数 字:"^\d{n}$&qu ...

  2. 用java做的免费投票器&sol;软件&sol;工具 可定制

    免费投票器/软件/工具 可定制 下载地址: http://pan.baidu.com/s/1c0je5HY 界面预览:

  3. iOS开发之总结

    NO.1 要孜孜不倦的学习有句话叫技多不压身,编程本来就是一个更新换代非常快的工作.每年都有新的技术出现,我认为要成为一个出色的程序员只掌握一门语言肯定是不行的.那么,要怎么选择自己的第二门,甚至第三 ...

  4. yii 验证器和验证码

    http://www.yiiframework.com/doc/api/1.1/CCaptcha http://www.cnblogs.com/analyzer/articles/1673015.ht ...

  5. J2SE知识点摘记&lpar;十&rpar;

    1.        多线程的同步 2.        同步代码块 即程序中不能有多个线程同时在这两句代码之间执行.(必须两句代码执行完,其他线程才可以公用执行) 同步代码块定义语法如下 ... syn ...

  6. MongDb添加嵌套文档

         想添加嵌套文档,就需要创建2个实体类.如下图 usermodel.Student = student; 其中Student的类型就是StudentModel: 第一个实体类         ...

  7. Web前端开发的一点记录

    工欲善其事必先利其器,开发工具选择Sublime Text 简称(ST) 本文所说的均在Windows NT 环境下使用的ST3运行. ST的Package Control安装方法: 1. 直接输入p ...

  8. Win10解决无法访问其他机器共享的问题

    Win10解决无法访问其他机器共享的问题     你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问.这些策略可帮助保护你的电脑免受网络上不安全设备或恶意设备的威胁. 管理员身份执 ...

  9. Eclipse里如何配制项目在tomcat中启动

    首先,在Eclipse中新建一个Hello工程,Workspace的位置在c:/eclipse/workspace,所以hello工程的位置就是在%Workspace%/hello/这个文件夹中.  ...

  10. AngularJS实现跨域请求

    跨域,前端开发中经常遇到的问题,AngularJS实现跨域方式类似于Ajax,使用CORS机制. 下面阐述一下AngularJS中使用$http实现跨域请求数据. AngularJS XMLHttpR ...