• Factors of Factorial


    问题 G: Factors of Factorial

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 54  解决: 31
    [提交][状态][讨论版][命题人:admin]

    题目描述

    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个质因子组成的数

    所以遍历2到n有多少个质因数

    例如样例3的阶乘为6  答案为4  : 1 2 3 6;

    质因数2有2个 3有2个 存入a[2] = 2;a[3] = 2

    总的个数就是2和3 选不同个数相乘得到的数 1就是2选0个 3选0个

    所以每个质因子都可以选0到a[i]个 共a[i]+1种选择

    相乘得答案

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    const long long int mm = 1e9+7;
    
    int main()
    {
        int n;
        int a[100005];
        scanf("%d",&n);
        memset(a,0,sizeof(a));
        for(int i=2;i<=n;i++)
        {
            int temp = i;
            while(temp!=1)
            {
                for(int j=2;j<=temp;j++)
                {
                    if(temp%j==0)
                    {
                        a[j]++;
                        temp/=j;
                        break;
                    }
                }
            }
        }
        
        long long int ans = 1; 
        for(int i=2;i<=n;i++)
        {
            ans*=a[i]+1;
            ans%=mm;
        }
        printf("%lld",ans);
    }

    分类:质因数分解

  • 相关阅读:
    工作杠杆
    AngularJS 自定义指令directive 介绍
    CentOS卸载OpenJDK并安装Sun JDK
    jQuery Datatable 表格插件
    ZTree 使用范例
    jQuery UI 实例 – 切换(Toggle)
    curl 抓取页面信息
    报警平台
    PHP imagechar() 图形验证码 字体太小问题
    Discuz!在线中文分词服务
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9121849.html
Copyright © 2020-2023  润新知