B

Problem Statement

 

You are given an integer N. Find the number of the positive divisors of N!, modulo 109+7.

Constraints

 

  • 1≤N≤103

Input

 

The input is given from Standard Input in the following format:

N

Output

 

Print the number of the positive divisors of N!, modulo 109+7.

Sample Input 1

 

3

Sample Output 1

 

4

There are four divisors of 3! =6123 and 6. Thus, the output should be 4.

Sample Input 2

 

6

Sample Output 2

 

30

Sample Input 3

 

1000

Sample Output 3

 

972926972

题解:

先说基本定理:

若正整数n可分解为p1^a1*p1^a2*...*pk^ak

其中pi为两两不同的素数,ai为对应指数,则n的约数个数为(1+a1)*(1+a2)*....*(1+ak)
        如180=2*2*3*3*5=2^2*3^2*5
        180的约数个数为(1+2)*(1+2)*(1+1)=18个。

        若求A/B的约数个数,A可分解为p1^a1*p2^a2*...*pk^ak,B可分解为q1^b1*q1^b2*...*qk^bk,

        则A/B的约数个数 为(a1-b1+1)*(a2-b2+1)*(a3-b3+1)...*(ak-bk+1).

然后说N的阶乘:

例如:20!
1.先求出20以内的素数,(2,3,5,7,11,13,17,19)
2.再求各个素数的阶数
e(2)=[20/2]+[20/4]+[20/8]+[20/16]=18;
e(3)=[20/3]+[20/9]=8;
e(5)=[20/5]=4;
...
e(19)=[20/19]=1;
所以
20!=2^18*3^8*5^4*...*19^1

解释:
2、4、6、8、10、12、14、16、18、20能被2整除
4、8、12、16、20能被4整除(即被2除一次后还能被2整除)
8、16能被8整除(即被2除两次后还能被2整除)
16能被16整除(即被2除三次后还能被2整除)
这样就得到了2的阶。其它可以依次递推。

AC代码

 1 #include<bits/stdc++.h>
 2 #define LL long long 
 3 using namespace std;
 4 
 5 const int MOD = 1e9+7;
 6 const int MAX = 1e6+10;
 7 const int INF = 0x3fffffff;
 8 bool a[MAX];
 9 
10 int C(int a,int b){
11     if(a<b) return 0;
12     else return a/b+C(a/b,b);
13 }//求n!的情况下, b的阶数
14 void init(){
15     memset(a,true,sizeof(a));
16     a[0]=a[1]=false;
17     for(int i=2;i<=MAX;i++){
18         if(a[i]){
19             for(int j=i+i;j<MAX;j+=i){
20                 a[j]=false;
21             }
22         }
23     }
24 }//把质数打表
25 int main(){
26     int n;
27     init();
28     while(scanf("%d",&n)!=EOF){
29         LL sum=1;
30         int i=2;
31         while(i<=n){
32             if(a[i]){/若a[i]是质数
33                 sum=sum*(LL)(C(n,i)+1)%MOD;//相乘。
34             }
35             i++;
36         } 
37         printf("%lld
",sum);
38     }
39 
40     return 0;
41 }
View Code
永远渴望,大智若愚(stay hungry, stay foolish)
原文地址:https://www.cnblogs.com/h-hkai/p/8552259.html