結果

問題 No.2365 Present of good number
ユーザー i_am_noob
提出日時 2023-06-30 21:41:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,113 bytes
コンパイル時間 2,309 ms
コンパイル使用メモリ 199,724 KB
最終ジャッジ日時 2025-02-15 03:38:42
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

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";
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0