結果

問題 No.2365 Present of good number
ユーザー momoyuu
提出日時 2023-10-25 15:35:10
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 2,703 ms
コンパイル使用メモリ 246,972 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 05:53:11
合計ジャッジ時間 4,105 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#include<atcoder/modint>
using mint = atcoder::modint1000000007;


ll modpow(ll n,ll k,ll mod){
    ll res = 1;
    while(k){
        if(k&1) res = (res*n)%mod;
        n = (n*n)%mod;
        k>>=1;
    }
    return res%mod;
}

mint calc(ll n,ll a,ll k){
    if(k==0) return mint(n).pow(a);
    if(n==2){
        ll can = k >> 1;
        const ll use = 1000000006;
        ll c = modpow(2,can,use);
        c = (c*a) % use;
        if(k&1) return mint(3).pow(c);
        else return mint(2).pow(c);
    }
    ll m = n + 1;
    mint res = 1;
    while(m%2==0){
        res *= calc(2,a,k-1);
        m /= 2; 
    }
    if(m!=1) res *= calc(m,a,k-1);
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 

    ll n,k;
    cin>>n>>k;
    mint ans = 1;
    for(int i = 2;i<=n;i++){
        if(n%i!=0) continue;
        while(n%i==0){
            ans *= calc(i,1,k);
            n /= i;
        }
    }
    cout<<ans.val()<<endl;
}
0