Codeforces#232 B

B. On Sum of Fractions
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's assume that

  • v(n) is the largest prime number, that does not exceed n;
  • u(n) is the smallest prime number strictly greater than n.

Find .

Input

The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.

Each of the following t lines of the input contains integer n (2 ≤ n ≤ 109).

Output

Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.


这题很有意思。。把那些写出来就是。。。假设qi是所有质数
ans = (q2-q1)/q1q2 + (q3-q2)/q2q3 + ....
而这个(q2-q1)/q1q2 + (q3-q2)/q2q3 = (q3-q1)/q1q3....
然后,还要我说吗?

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<string>

#define LL long long

using namespace std;

const int isOJ = 1,Debug = 0;

bool isPrime(LL k){
	LL i;
	for (i = 2;i*i <= k;i++)
		if (k % i == 0)
			return 0;
	return 1;
}
LL gcd(LL a,LL b){
	if (b == 0)
		return a;
	else
		return gcd(b,a%b);
}

int cas;

int Work(){
	LL n,minp,maxp,a1,b1,a2,b2,a3,b3,t;
	cin >> n;
	minp = n;maxp = n+1;
	while(!isPrime(minp)) minp--;
	while(!isPrime(maxp)) maxp++;
	a1 = minp - 2;
	b1 = minp * 2;
	t = gcd(a1,b1);
	a1 /= t;
	b1 /= t;
	a2 = n - minp + 1;
	b2 = maxp * minp;
	t = gcd(a2,b2);
	a2 /= t;
	b2 /= t;
	t = gcd(b1,b2);
	a3 = a1 * (b2/t) + a2 * (b1/t);
	b3 = b1 / t * b2 ;
	//cout << a3 << "fuck" << b3 << endl;
	t = gcd(a3,b3);
	a3 /= t;
	b3 /= t;
	cout << a3 << "/" << b3 << endl;
	return 1;
}

int main(){
	if (!isOJ)
		freopen("/Users/mac/Desktop/test.in","r",stdin);
	cin >> cas;
	while(cas--) Work();
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值