You are given an integer N. Find the number of the positive divisors of N!, modulo 109+7.
Constraints
1≤N≤103
标签:void wing oid ace you include stream stand amp
3
4
There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.
思路:将N!分解质因数,比如6!=720=2*2*2*2*3*3*5,质因子2有4个,3有2个,5有1个,可以取0~4个2,0~2个3,0~1个5构成720的因子,跟据乘法原理,720的因子有(4+1)*(2+1)*(1+1)=30个;
AC代码:
#include <iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #define mod 1000000007 using namespace std; bool isprime[1010]; int num[1010]; void judge(){ for(int i=0;i<1010;i++) isprime[i]=1; isprime[0]=0; for(int i=2;i*i<1010;i++){ if(isprime[i]){ for(int j=i*i;j<1010;j+=i){ isprime[j]=0; } } } } void get_prime(int x){ for(int i=2;i<=x;i++){ if(isprime[i]&&x%i==0){ while(x%i==0){ num[i]++; x/=i; } } } } int main() { judge(); int n; scanf("%d",&n); if(n==1) {printf("1\n"); return 0;} for(int i=2;i<=n;i++){ get_prime(i); } long long ans=1; for(int j=2;j<=n;j++) if(vis[j]) ans=ans*(num[j]+1)%mod; cout<<ans<<endl; return 0; }
标签:void wing oid ace you include stream stand amp
原文地址:https://www.cnblogs.com/lllxq/p/9119359.html