2721: [Violet 5]樱花
Time Limit: 5 Sec Memory Limit: 128 MB[ Submit][ Status][ Discuss]
Description
Input
Output
Sample Input
Sample Output
HINT
Source
1/x + 1/y = 1/n!
因为x,y > 0
所以x,y > n!
设x = n! + a
1/(n!+a) + 1/y = 1/n!
y*n! + (n!+a)*n! = y*(n!+a)
y*a = (n!)^2 + a*n!
y = (n!)^2/a + n!
因为只有当a是(n!)^2的因数的时候,y是一个整数,且可以知道一个y被一个a唯一确定
所以答案就是(n!)^2的约数个数
一个数(p1^a1*p2^a2...pn^an)的约数个数就是(a1+1)*(a2+1)*...*(an+1)
然后如何计算n!对于pi的指数
加上n/pi,n/pi^2.....直到n<=pi^x
就完了
此题没有样例差评
#include<bits/stdc++.h>
using namespace std;
const int N = 1000000 + 6;
const int mod = 1000000000 + 7;
int n,pri[N],tot,ans=1; bool isnot[N];
void init( int x ){
for( int i = 2; i <= x; i++ ){
if( !isnot[i] ) pri[++tot] = i;
for( int j = 1; j <= tot && i * pri[j] <= x; j++ ){
isnot[i*pri[j]] = 1;
if( i % pri[j] == 0 ) break;
}
}
}
int main(){
scanf("%d", &n );
init(n);
for( int i = 1; i <= tot; i++ ){
int tmp = n; long long cnt = 0;
while( tmp ){
cnt += tmp / pri[i], tmp /= pri[i];
}
cnt = 1LL * ( ( cnt << 1 ) + 1 ) % mod;
ans = 1LL* ans * cnt % mod;
}
cout<<ans<<endl;
return 0;
}