题目链接
题目意思:
水一下
题目意思:
定义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 **/
/**************************************************/
水一下