BZOJ2721 樱花 [线性筛]


2721: [Violet 5]樱花

Time Limit: 5 Sec   Memory Limit: 128 MB
Submit: 646   Solved: 378
[ Submit][ http://www.lydsy.com/JudgeOnline/problemstatus.php?id=2721‘>Status][ http://www.lydsy.com/JudgeOnline/bbs.php?id=2721‘>Discuss]

Description

Input

Output

题意就是求有多少正整数数对 (x,y) 满足

1x+1y=1n!

由于x,y>0,故显然有y>n!
不妨设y=n!+t(t>0),那么有
1x+1n!+t=1n!
化简后得到
n!(n!+t)+x(n!)=x(n!+t)
x=(n!)2t+n!
故答案为d((n!)2)
我们令
y=n!+t(t>0)

=>1x+1n!+t=1n!

那么
=>x(n!)+n!(n!+t)=x(n!+t)

=>x=(n!)2t+n!=>(n!)(2t+1)

#include
using namespace std;
const int N = 1001005,mod = 1000000007;
int primes,prime[N],n,m;
long long ans=1,tmp,ret;
bool vis[N];
void init(){
    for(register int i=2;i<=n;i++){
        if(!vis[i])prime[++primes]=i;
        for(register int j=1;prime[j]*i<=n;j++){
            vis[prime[j]*i]=1;
            if(i%prime[j]==0)break;
        }
    }
}
int main(){
    scanf("%d",&n);
    init();
    for(register int i=1;i<=primes;i++){
        tmp=n,ret=0;
        while(tmp)ret+=tmp/prime[i],tmp/=prime[i];
        ret=(ret<<1|1)%mod;
        ans*=ret;ans%=mod;
    }
    printf("%lld\n",ans);
    return 0;
}

BZOJ2721 樱花 [线性筛]_第1张图片

你可能感兴趣的:(BZOJ,线性筛)