题目链接



题目意思:

定义v(n)是不超过n的最大素数, u(n)是大于n的最小素数。

以分数形式"p/q"输出 sigma(i = 2 to n) (1 / (v(i)*u(i))), pq为互质整数且q > 0。

通常会想到这个裂项。公式一写发现约掉了许多。

最终是:

所以:AC 注意乘的过程会爆int。

#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h> using namespace std;
typedef long long LL;
const int INF=2e9+1e8;
const int MOD=1e9+7;
const int MAXSIZE=1e6+5;
const double eps=0.0000000001;
void fre()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
}
#define memst(a,b) memset(a,b,sizeof(a))
#define fr(i,a,n) for(int i=a;i<n;i++) bool isprime(int n)
{
for(int i=2;i*i<=n;i++) if(n%i==0) return false;
return true;
}
LL gcd(LL a,LL b)
{
return __gcd(a,b);
}
int main(int argc,char *argv[])
{
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
int n;
scanf("%d",&n);
int z,m;
z=m=n;
m++;
while(!isprime(z)) z--;
while(!isprime(m)) m++;
LL fz,fm;
fz=1ll*z*m-2ll*z-2ll*(m-n-1ll);
fm=2ll*z*m;
LL temp=gcd(fz,fm);
cout<<fz/temp<<"/"<<fm/temp<<endl;
}
return 0;
} /**************************************************/
/** Copyright Notice **/
/** writer: wurong **/
/** school: nyist **/
/** blog : http://blog.csdn.net/wr_technology **/
/**************************************************/

水一下


数学题--On Sum of Fractions的更多相关文章

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

  2. Codeforces 396B On Sum of Fractions 数论

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

  3. cf D. On Sum of Fractions

    http://codeforces.com/problemset/problem/397/D 题意:v(n) 表示小于等于n的最大素数,u(n)表示比n的大的第一个素数,然后求出: 思路:把分数拆分成 ...

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

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

  6. Miller Rabin 详解 && 小清新数学题题解

    在做这道题之前,我们首先来尝试签到题. 签到题 我们定义一个函数:\(qiandao(x)\) 为小于等于 x 的数中与 x 不互质的数的个数.要求 \(\sum\limits _{i=l}^r qi ...

  7. Codeforces Round #232 (Div. 1)

    这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...

  8. WannaflyUnion每日一题

    ---恢复内容开始--- 1. http://www.spoj.com/problems/KAOS/ 题意:给定n个字符串,统计字符串(s1, s2)的对数,使得s1的字典序比s2的字典序要大,s1反 ...

  9. hdu 4961 Boring Sum(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4961 Problem Description Number theory is interesting ...

随机推荐

  1. Android—一次清除所有Activity

    首先,自定义一个ActivityManager管理类,用于管理栈中的Activity public class ActivityManager{ private static final String ...

  2. Spring学习资料

    1.马士兵视频 2.SPRING技术内幕__深入解析SPRING架构与设计原理 3.jinnianshilongnian博客 4.Spring实战 (Spring IN Action) 5.官方文档

  3. windows forget jenkins password.

    1. goto the directory of jenkins. for example my installation is in D:\Program Files (x86)\Jenkins. ...

  4. MOS管驱动详解

    1.常用的几种电平转换方案 2.三极管的电平转换及驱动电路分析 3.三级管老怀 4.关于MOSFET管驱动电路总结 5.一个IIC的5V和3.3V电平转换的经典电路分享 6.mos 7.mos应用 8 ...

  5. 如何将安卓手机中已安装的应用导出一个apk安装包

    首先安装ES文件浏览器 然后应用里找到你要导出apk的应用,长按应用,备份应用, 然后在upbacks/apps文件夹里找吧 不得不说 ES浏览器还是屌啊

  6. vs2012停止调试长时间不响应问题解决方法

    在vs2012命令提示符下,运行devenv.exe /resetuserdata又一次设置下环境解决.

  7. Django-extra的用法

    ## select提供简单数据 # SELECT age, (age > 18) as is_adult FROM myapp_person; Person.objects.all().extr ...

  8. 在html文件引入其它html文件的几种方法

    1.IFrame引入,看看下面的代码 <IFRAME NAME="content_frame" width=100% height=600 marginwidth=0 mar ...

  9. jackrabbit官方英文文档加补充(转载)

    关于Jackrabbit To get started with Jackrabbit you should first become familiar with the JCR API. Downl ...

  10. Jquery源码分析-整体结构

    最近在学习Jquery的最新的源码,Jquery-3.3.1版本.网上有很多对jquery解析的文章.但是我还是要自己去尝试着看一篇jquery的源码.本系列博客用来记录其中的过程,并同大家分享.本次 ...