AtCoder - 2286 (number theory - the only decomposition theorem)

The meaning of problems

The number of factors find the n!% 1e9 + 7.

Thinking

By a unique decomposition theorem, it can be split into a number of powers of prime product, i.e., 2 ^ a * 3 ^ b * ......, n! = 2 * 3 * ...... * n, so that for each prime factor calculating these numbers appear in the total number of (direct factorization 2 ~ n can), then the only decomposition theorem equation, the number of factor = (a + 1) * (b + 1) * .......

Code

#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;
}

  

Guess you like

Origin www.cnblogs.com/mcq1999/p/11843272.html