結果
| 問題 | No.28 末尾最適化 |
| コンテスト | |
| ユーザー |
Yang33
|
| 提出日時 | 2018-04-09 19:03:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,715 ms / 5,000 ms |
| コード長 | 2,566 bytes |
| 記録 | |
| コンパイル時間 | 2,167 ms |
| コンパイル使用メモリ | 177,824 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-26 20:43:35 |
| 合計ジャッジ時間 | 3,913 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2018/04/09 Problem: yukicoder 028 / Link: http://yukicoder.me/problems/no/028 ----- */
/* ------問題------
ただし % は剰余演算とする
上の定義から作られる N+1 個の要素を持つ数列 X の中から K 個数字を選びそれらを掛け合わせ T とおく。
T を B 進数に変換した時末尾の0の数が最小となる T では末尾の0の数はいくつになるか答えよ。
例えば
B=18、T が10進数で「612」なら T は18進数で「1g0」なので末尾の0の数は1個
B=3、T が10進数で「36」なら T は3進数で「1100」なので末尾の0の数は2個
-----問題ここまで----- */
/* -----解説等-----
----解説ここまで---- */
LL N;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int Q; cin >> Q;
const LL mod = 100000009;
FOR(q, 0, Q) {
LL seed, N, K, B;
cin >> seed >> N >> K >> B;
LL BB = B;
VI b(B + 1, 0);
for (int i = 2; i <= BB; i++) {
while (B%i == 0) {
b[i]++;
B /= i;
}
}
VL x(N + 1);
x[0] = seed;
FOR(i, 1, N + 1) {
x[i] = 1 + (x[i - 1] * x[i - 1] + x[i - 1] * 12345) % mod;
}
B = BB;
VVI bx(B + 1, VI(N + 1, 0));
//VVI xb(N + 1, VI(B + 1, 0));
FOR(i, 0, N + 1) {
for (int j = 2; j <= B; j++) {
while (x[i] % j == 0) {
bx[j][i]++;
x[i] /= j;
}
}
}
int ans = INF;
FOR(i, 2, B + 1) {
if (b[i]) {
int Base = b[i];
sort(bx[i].begin() , bx[i].end());
int ret = 0;
FOR(k, 0, K) {
ret += bx[i][k];
}
ans = min(ans, ret / Base);
}
}
cout << ans << "\n";
}
return 0;
}
Yang33