数学题--On Sum of Fractions
题目意思:
定义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的更多相关文章
- 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 D. On Sum of Fractions
http://codeforces.com/problemset/problem/397/D 题意:v(n) 表示小于等于n的最大素数,u(n)表示比n的大的第一个素数,然后求出: 思路:把分数拆分成 ...
- 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 ...
- Miller Rabin 详解 && 小清新数学题题解
在做这道题之前,我们首先来尝试签到题. 签到题 我们定义一个函数:\(qiandao(x)\) 为小于等于 x 的数中与 x 不互质的数的个数.要求 \(\sum\limits _{i=l}^r qi ...
- Codeforces Round #232 (Div. 1)
这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...
- WannaflyUnion每日一题
---恢复内容开始--- 1. http://www.spoj.com/problems/KAOS/ 题意:给定n个字符串,统计字符串(s1, s2)的对数,使得s1的字典序比s2的字典序要大,s1反 ...
- hdu 4961 Boring Sum(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4961 Problem Description Number theory is interesting ...
随机推荐
- Caused by: java.io.FileNotFoundException: rmi_keystore.jks (没有那个文件或目录)
解决方法:修改jmeter.properites: server.rmi.ssl.disable=true,关闭ssl功能 参考: https://blog.csdn.net/nielinqi520/ ...
- php自己编译安装后,再给这个编译安装的php版本添加拓展模块的处理办法。
原文: https://www.cnblogs.com/zongyl/p/5924627.html 说明,给编译安装之后的php 添加pgsql 拓展成功. --------------------- ...
- ItelliJ IDEA开发工具使用—创建一个web项目
转 http://blog.csdn.net/wangyang1354/article/details/50452806 最近想用IDEA编辑器开发,但是平时都用MyEclipse和eclipse ...
- ZipOutputStream 用法 小计
ZipOutputStream s = new ZipOutputStream(File.Create(ZipedFile)); 构造函数之后 文件就已经创建出来了 只是 0kb s.Write(bu ...
- final 和static
一.final 1.final变量: 当你在类中定义变量时,在其前面加上final关键字,那便是说,这个变量一旦被初始化便不可改变,这里不可改变的意思对基本类型来说是其值不可变,而对于对象变量来说其引 ...
- Spark技术内幕: Task向Executor提交的源代码解析
在上文<Spark技术内幕:Stage划分及提交源代码分析>中,我们分析了Stage的生成和提交.可是Stage的提交,仅仅是DAGScheduler完毕了对DAG的划分,生成了一个计算拓 ...
- tensor搭建--windows 10 64bit下安装Tensorflow+Keras+VS2015+CUDA8.0 GPU加速
windows 10 64bit下安装Tensorflow+Keras+VS2015+CUDA8.0 GPU加速 原文见于:http://www.jianshu.com/p/c245d46d43f0 ...
- Linux内核RCU(Read Copy Update)锁简析
在非常早曾经,大概是2009年的时候.写过一篇关于Linux RCU锁的文章<RCU锁在linux内核的演变>,如今我承认.那个时候我尽管懂了RCU锁,可是我没有能力用一种非常easy的描 ...
- Apache Server与多个独立Tomcat集成
取经自http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html 继续干Tomcat和Apache Se ...
- asp识别手机端
<script type="text/javascript"> var mobileAgent = new Array("iphone", &quo ...