AtCoder - 2286 (数论——唯一分解定理)

题意

求n!的因子数%1e9+7。

思路

由唯一分解定理,一个数可以拆成素数幂之积,即2^a * 3^b *……,n!=2*3*……*n,所以计算每个素因子在这些数中出现的总次数(直接对2~n素因子分解即可),再用唯一分解定理公式,因子数=(a+1)*(b+1)*……。

代码

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int a[N];
int main()
{
    std::ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        int ii=i;
        for(int j=2;j<=i;j++)
        {
            while(ii%j==0)
            {
                a[j]++;
                ii/=j;
            }
        }
    }
    ll ans=1;
    for(int i=2;i<=n;i++)
    {
    //    cout<<a[i]<<endl;
        ans=(ans*(a[i]+1))%mod;
    }
    cout<<ans<<endl;
    return 0;
}

  

posted @ 2019-11-12 17:05  MCQ1999  阅读(286)  评论(0编辑  收藏  举报