Factors of Factorial

问题 H: Factors of Factorial

时间限制: 1 Sec 内存限制: 128 MB
[提交] [状态]
题目描述
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.
样例输入 Copy
3
样例输出 Copy
4
提示
There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.

先说基本定理:
若正整数n可分解为p1a1*p1a2*…pk^ak
其中pi为两两不同的素数,ai为对应指数,则n的约数个数为(1+a1)
(1+a2)(1+ak)
如180=22335=22*325
180的约数个数为(1+2)
(1+2)(1+1)=18个。
若求A/B的约数个数,A可分解为p1a1*p2a2
pkak,B可分解为q1b1q1b2*…*qkbk,
则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!=218*38*54*…*191

解释:
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的阶。其它可以依次递推。

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
#define mod 1000000007
#define ll long long
const int MAX_N=1e6+5;
const int INF = 0x3f3f3f;
bool a[MAX_N];
int n;

int f(int x,int y){
    if(x<y) return 0;
    return x/y+f(x/y,y);
}

void init()
{
    memset(a,true,sizeof a);
    a[0]=false;
    a[1]=false;
    for(int i=2;i<=MAX_N;i++)
    {
        if(a[i])
        {
            for(int j=i+i;j<MAX_N;j+=i)
            {
                a[j]=false;
            }
        }
    }
}

int main()
{
    init();
    cin>>n;
    ll sum=1;
    int i=2;
    while(i<=n)
    {
        if(a[i]){
            sum=sum*(ll)(f(n,i)+1)%mod;
        }
        i++;
    }
    cout<<sum;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值