結果
| 問題 | No.28 末尾最適化 |
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-16 23:02:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 388 ms / 5,000 ms |
| コード長 | 1,520 bytes |
| 記録 | |
| コンパイル時間 | 806 ms |
| コンパイル使用メモリ | 71,908 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-12-31 21:18:56 |
| 合計ジャッジ時間 | 1,614 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d", &Q);
| ~~~~~^~~~~~~~~~
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%lld %d %d %lld", &seed, &N, &K, &B);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
typedef long long ll;
typedef std::pair<int,int> P;
const ll MOD = 100000009ll;
int main(){
int Q;
scanf("%d", &Q);
for(int _=0;_<Q;_++){
ll seed, B;
int N, K;
scanf("%lld %d %d %lld", &seed, &N, &K, &B);
std::vector<ll> v(N+1);
v[0] = seed;
for(int i=1;i<=N;i++){
v[i] = 1 + (v[i-1]*v[i-1]%MOD + v[i-1]*12345%MOD) % MOD;
}
std::vector<P> fs;
for(int i=2;i*i<=B;i++){
if(B % i == 0){
int t = 0;
while(B % i == 0){t += 1; B /= i;}
fs.push_back(std::make_pair(i, t));
}
}
if(B > 1){fs.push_back(std::make_pair(B, 1));}
// for(auto f : fs){
// printf("%d %d\n", f.first, f.second);
// }
std::vector<int> v2(N+1);
int res = 1001001001;
for(auto f : fs){
int p = f.first, q = f.second;
for(int i=0;i<N+1;i++){
ll x = v[i];
int t = 0;
while(x % p == 0){t += 1; x /= p;}
v2[i] = t;
}
std::sort(v2.begin(), v2.end());
int sum = 0;
for(int i=0;i<K;i++){
sum += v2[i];
}
res = std::min(res, sum/q);
}
printf("%d\n", res);
}
}
tottoripaper