Problem Statement
Constraints
Input
Output
Sample Input 1
Sample Output 1
Sample Input 2
Sample Output 2
Sample Input 3
Sample Output 3
You are given an integer N. Find the number of the positive divisors of N!, modulo109+7.
- 1≤N≤103
The input is given from Standard Input in the following format:
N
Print the number of the positive divisors of N!, modulo 109+7.
3
4
There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.
6
30
1000
972926972
求一个数的阶乘的因子有多少个,为了去重,可以将这个数表示成素因子的乘积
将 N 分解质因子后得到这样的格式:N=2a×3b×5c×7d×...
那么约数个数为(a+1)×(b+1)×(c+1)×...
因为对于每一个素因子,比如 2,我们可以选择 0~a 个,根据乘法原理,就得到了上面的式子
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int N = 1e5+10;
typedef long long LL;
const LL mod = 1e9+7;
int a[N];
int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
for(int i=2;i<=n;i++)
{
int x=i;
for(int j=2;j<=x;j++)
{
while(x%j==0)
{
a[j]++;
x/=j;
}
}
if(x!=1) a[x]++;
}
LL ans=1;
for(int i=1;i<=n;i++)
{
if(a[i]!=0) ans=(ans*(a[i]+1))%mod;
}
printf("%lld\n",ans);
}
return 0;
}