結果
| 問題 |
No.28 末尾最適化
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2022-05-29 18:41:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 686 ms / 5,000 ms |
| コード長 | 1,336 bytes |
| コンパイル時間 | 2,100 ms |
| コンパイル使用メモリ | 198,836 KB |
| 最終ジャッジ日時 | 2025-01-29 16:58:56 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
using ll=long long;
vector<pair<int,int>> P[37];
const ll MOD=100000009;
template<typename T,typename Comp>
using pque=priority_queue<T,vector<T>,Comp>;
pque<int,greater<>> que[3];
int solve(){
ll s,n,k,b;cin>>s>>n>>k>>b;
REP(_,n+1){
//cerr<<s<<endl;
ll cpy=s;
REP(i,P[b].size()){
int cnt=0;
while(cpy%P[b][i].first==0){
cnt++;
cpy/=P[b][i].first;
}
//cerr<<P[b][i].first<<":"<<cnt<<endl;
que[i].push(cnt);
}
s=1+ s*(s+12345)%MOD;
}
int res=1e9;
REP(i,P[b].size()){
int cnt=0;
REP(_,k){
cnt+=que[i].top();que[i].pop();
}
while(que[i].size())que[i].pop();
//cerr<<cnt<<","<<P[b][i].first<<","<<P[b][i].second<<endl;
res=min(res,cnt/P[b][i].second);
}
return res;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
for(int b=2;b<=36;b++){
int now=b;
for(int i=2;i<=36;i++){
if(now%i)continue;
int cnt=0;
while(now%i==0){
now/=i;
cnt++;
}
P[b].emplace_back(i,cnt);
}
}
for(int b=2;b<=36;b++){
//cerr<<b<<":";for(const auto&[a,c]:P[b])cerr<<"["<<a<<","<<c<<"]";
//cerr<<endl;
}
int testsize;cin>>testsize;
while(testsize--)cout<<solve()<<'\n';
}
cureskol