結果

問題 No.2365 Present of good number
ユーザー i_am_noobi_am_noob
提出日時 2023-06-30 21:41:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,113 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 204,664 KB
実行使用メモリ 4,628 KB
最終ジャッジ日時 2023-09-21 15:35:13
合計ジャッジ時間 3,559 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,628 KB
testcase_05 AC 3 ms
4,556 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,520 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

const int N=100005;
const int mod=1000000007;
int add(int x, int y){x+=y; if(x>=mod) x-=mod; return x;}
int sub(int x, int y){x-=y; if(x<0) x+=mod; return x;}
int mul(int x, int y){return ((ll)x)*y%mod;}
int fpow(int x, ll y, int m){int res=1; for(; y; x=1ll*x*x%m,y>>=1) if(y&1) res=1ll*res*x%m; return res;}
vector<int> pr;
int lpd[N];
void sieve(){
    pr.clear();
    for(int i=0; i<N; ++i) lpd[i]=-1;
    for(int i=2; i<N; ++i){
        if(lpd[i]==-1) lpd[i]=i,pr.pb(i);
        for(auto p: pr){
            if(p*i>=N) break;
            lpd[p*i]=p;
            if(i%p==0) break;
        }
    }
}
vector<int> factors(int x){
    vector<int> res;
    while(x>1) res.pb(lpd[x]),x/=lpd[x];
    return res;
}

int n;
vector<int> cnt;
ll k;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    sieve();
    cin >> n >> k;
    auto vec=factors(n);
    cnt.resize(vec.back()+1);
    for(auto p: vec) cnt[p]++;
    while(cnt.back()==0) cnt.pop_back();
    while(k){
        if(sz(cnt)<=4){
            cnt.resize(4);
            if(k&1){
                int res1=fpow(3,1ll*cnt[2]*fpow(2,k/2,mod-1)%(mod-1),mod);
                int res2=fpow(2,1ll*cnt[3]*fpow(2,(k+1)/2,mod-1)%(mod-1),mod);
                cout << mul(res1,res2) << "\n";
                return 0;
            }
            else{
                int res1=fpow(2,1ll*cnt[2]*fpow(2,k/2,mod-1)%(mod-1),mod);
                int res2=fpow(3,1ll*cnt[3]*fpow(2,k/2,mod-1)%(mod-1),mod);
                cout << mul(res1,res2) << "\n";
                return 0;
            }
        }
        vector<int> ncnt(sz(cnt)+1);
        for(int i=2; i<sz(cnt); ++i) if(cnt[i]>0){
            auto vec=factors(i+1);
            for(auto p: vec) ncnt[p]+=cnt[i];
        }
        cnt=ncnt;
        while(cnt.back()==0) cnt.pop_back();
        k--;
    }
    int res=1;
    for(int i=2; i<sz(cnt); ++i) if(cnt[i]>0) res=mul(res,fpow(i,cnt[i],mod));
    cout << res << "\n";
}
0