[数论]Factors of Factorial

Posted lz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[数论]Factors of Factorial相关的知识,希望对你有一定的参考价值。

题目描述

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

Constraints
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.

思路:将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;
}

以上是关于[数论]Factors of Factorial的主要内容,如果未能解决你的问题,请参考以下文章

1096 Consecutive Factors (20 分)难度: 一般 / 爆搜 数论

HDU 1124 Factorial(简单数论)

洛谷 P3927 SAC E#1 - 一道中档题 Factorial数论//

[Algorithm] Finding all factors of a number

Disentangling the independently controllable factors of variation by interacting with the world

lightoj-1045 - Digits of Factorial(利用对数)