• [数论]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
    "); 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;
    }
    转载请注明出处:https://www.cnblogs.com/lllxq/
  • 相关阅读:
    Oracle导出txt文本文件
    oracle spool
    [Oracle, MySQL] Oracle通过dblink连接MySQL
    正则表达式速查表
    常用的正则表达式
    python3 打印九九乘法口诀表
    canda 常用命令
    python3 拼接字符串的7种方法
    Python 字符串格式化输出方式
    PyCharm 解决有些库(函数)没有代码提示
  • 原文地址:https://www.cnblogs.com/lllxq/p/9119359.html
Copyright © 2020-2023  润新知