2721: [Violet 5]樱花

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 499  Solved: 293
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

 3

Sample Output

 9

HINT

Source

interviewstreet--EQUATIONS

Solution

巧妙!

$\frac{1}{x}+\frac{1}{y}=\frac{1}{n!}$ 令$z=n!$

则可以得到$\frac{1}{x}+\frac{1}{y}=\frac{1}{z}=>x=\frac{yz}{y-z}$

再另$t=y-z$则可以得到$x=z+\frac{z^{2}}{t}$

所以我们求$n!^{2}$的约数,就是答案,这就利用到线筛

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define P 1000000007
#define LL long long
int N,cnt,prime[],z[],tmp;
bool flag[];
LL ans=1LL;
void Getprime()
{
flag[]=; cnt=;
for (int i=; i<=N; i++)
{
if (!flag[i]) prime[++cnt]=i;
for (int j=; j<=cnt && prime[j]*i<=N; j++)
{
flag[i*prime[j]]=;
if (prime[j]%i==) break;
}
}
}
void Calc(int x)
{
for (int i=prime[x]; i<=N; i+=prime[x])
for (int j=i; j%prime[x]==; j/=prime[x]) z[x]++;
}
int main()
{
scanf("%d",&N);
Getprime();
for (int i=; i<=cnt; i++) Calc(i);
for (int i=; i<=cnt; i++) printf("%d ",z[i]); puts("");
for (int i=; i<=cnt; i++) ans=((LL)ans*(z[i]<<|)%P)%P;
printf("%lld\n",ans);
return ;
}