C - Factors of Factorial
Time Limit: 2 sec / Memory Limit: 256 MB
Score : points
Problem Statement You are given an integer . Find the number of the positive divisors of , modulo .
Constraints
Input The input is given from Standard Input in the following format:
Output Print the number of the positive divisors of , modulo .
Sample Input 1
3
Sample Output 1
4
There are four divisors of : , , and . Thus, the output should be .
Sample Input 2
6
Sample Output 2
30
Sample Input 3
1000
Sample Output 3
972926972
把N的阶乘写成质因子相乘的形式
思路:
N!=2^A+3^B+5^C+.....
然后因子个数就是(A+1)*(B+1)*... 2可以选0~A。
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int maxn=1e5+10;
int f[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=2;i<=n;i++)
{
int a=i;//4//---
for(int j=2;j<=a;j++)
{
while(!(a%j))
{
f[j]++;
a/=j;
}
}
if(a!=1)
f[a]++;
}
ll ans=1;
for(int i=1;i<=n;i++)
{
if(f[i])ans*=(1+f[i])%mod;
ans%=mod;
}
printf("%d\n",ans%mod);
}