数学题--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  **/
/**************************************************/



水一下

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值