結果

問題 No.1659 Product of Divisors
ユーザー 👑 Kazun
提出日時 2021-07-22 01:31:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 1,021 ms
コンパイル使用メモリ 72,924 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-21 00:06:24
合計ジャッジ時間 2,135 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;
using ll=long long;

ll pow_mod(ll a, ll n, ll m){
    if (n==0) return 1;
    else if (n%2==1) return (a*pow_mod(a,n-1,m))%m;
    else{
        ll y=pow_mod(a,n>>1,m);
        return (y*y)%m;
    }
}

ll nCr(ll n, ll r, ll m){
    ll a=1, b=1;
    while (r){
        a=(a*n)%m; b=(b*r)%m;
        n--; r--;
    }
    return (a*pow_mod(b,m-2,m))%m;
}

ll nHr(ll n, ll r, ll m){return nCr((n+r-1)%m,r%m,m);}

vector<pair<ll,ll>> Prime_Factorization(ll N) {
    vector<pair<ll,ll>> R;
    ll e=0;

    while (N%2==0){
        e++;
        N/=2;
    }
    R.push_back({2,e});

    e=0;
    while (N%3==0){
        e++;
        N/=3;
    }
    R.push_back({3,e});

    ll p=5,f=0;
    while (p*p<=N) {
        if (N % p==0){
            ll e=0;
            while (N % p == 0){
                e++;
                N/=p;
            }
            R.push_back({p,e});
        }
        p+=2+2*f;
        f^=1;
    }

    if (N != 1) R.push_back({N, 1});
    return R;
}

int main(){
    ll N,K;
    cin >> N >> K;

    ll Mod=1000000007;
    ll X=1;
    for (auto x:Prime_Factorization(N)){
        ll e=x.second;;
        X*=nHr(K+1,e,Mod);
        X%=Mod;
    }

    cout << X << endl;
}
0