题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1189
题目思路:
1/n! = 1/x +1/y

==> n! * (x + y) = x * y(右边通分。然后转化)

==> n!^2 = (x - n!)*(y - n!)(左右两边加上n方)

==> a = b * c ,a = n!^2 ,b = x - n! ,c = y - n!

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
const int maxn=1e6+5;
bool prime[maxn];
int p[maxn/10];
int k;
void isprime()
{
    k=0;
    LL i,j;
    memset(prime, true, sizeof(prime));
    for(i=2; i<maxn; i++)
    {
        if(prime[i])
        {
            p[k++]=i;
            for(j=i*i; j<maxn; j+=i)
            prime[j]=false;
        }
    }
    /*for(int i=0; i<10; i++)
    cout<<p[i]<<" ";*/
}
LL get(LL m, LL p)
{
    if(m<p)
    return 0;
    return m/p+get(m/p,p);
}
LL quickmod(LL a, LL b)
{
    LL ans = 1;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans ;
}
int main()
{
    isprime();
    int n;
    while(~scanf("%d",&n))
    {
        LL ans=1;
        LL m = quickmod(2,(LL)mod-2);
        for(int i=0; i<k&&p[i]<=n; i++)
        {
            LL tmp = (get(n,p[i])*2+1)%mod;
            ans=ans*tmp%mod;
        }
        ans = ans*m%mod;
        ans = (ans+m%mod)%mod;
        printf("%lld\n",ans);
    }
    return 0;
}
posted on 2017-06-12 09:11  yutingliuyl  阅读(245)  评论(0编辑  收藏  举报