数学题--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 ...
随机推荐
- SetProcessWorkingSetSize 和内存释放
http://hi.baidu.com/taobaoshoping/item/07410c4b6d6d9d0d6dc2f084 在应用程序中,往往为了释放内存等,使用一些函数,其实,对于内存操作函数要 ...
- Interface Builder中的技巧
在我工作中经常会遇到有人吐槽Xcode中的interface builder(以下简称IB)不好用的开发者.在我看来,IB是一个非常棒的可视化开发工具,可以非常快捷的设置UI控件的大部分常用属性.下面 ...
- 词典对象(NSDictionary和NSMutableDictionary)
词典(dictionary)顾名思义就是同由键-值组成的数据集合.与在词典中查找单词定义一样,可以通过对象的键从词典中获取需要的对象,看到 这里,你是不是想起了java中的map?和NSArray一样 ...
- iOS 推送 获取手机设备的 deviceToken
第一步:申请证书: 第二步:申请app ids,应用名字必须一致.然后再进入进行编辑.使其enable,绿灯. 第三步:申请provisioning profile,生成.mobileprovisio ...
- C 标准库 - <setjmp.h>
C 标准库 - <setjmp.h> 简介 setjmp.h 头文件定义了宏 setjmp().函数 longjmp() 和变量类型 jmp_buf,该变量类型会绕过正常的函数调用和返回规 ...
- spring secrity 一些常用小知识
1.在JSP页面获取当前登录的用户名的方法 首先引入taglib:<%@ taglib prefix="sec" uri="http://www.springfra ...
- 解题报告 之 HDU5288 OO' s Sequence
解题报告 之 HDU5288 OO' s Sequence Description OO has got a array A of size n ,defined a function f(l,r) ...
- inch mil mm换算
inch:英寸 mil:密耳 mm:毫米 1mil=0.0254mm=25.4um 1mm=39.37mil 1inch=1000mil=25.4mm
- FastDFS的配置、部署与API使用解读(6)FastDFS配置详解之Storage配置(转)
1 基本配置 disabled #func:该配置文件是否生效 #valu: ## true:无效 ## false:生效 disabled=false group_name #func:本stora ...
- Linux(centos 6.5) 调用java脚本以及定时运行的脚本实例及配置文件具体解释
Linux(centos 6.5) 调用java脚本以及定时运行的脚本实例 一.调用java程序脚本(默认已经搭建好了Java环境) 1.jdk 安装路径 /usr/jdk/jdk1.7/-- 2.j ...