結果
| 問題 | No.28 末尾最適化 |
| コンテスト | |
| ユーザー |
tnodino
|
| 提出日時 | 2022-02-13 14:19:03 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,006 bytes |
| コンパイル時間 | 101 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 20,176 KB |
| 最終ジャッジ日時 | 2024-06-29 05:35:14 |
| 合計ジャッジ時間 | 6,531 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 TLE * 1 |
ソースコード
from math import sqrt
from collections import defaultdict
def PrimeFactorization1(N):
ret = defaultdict(int)
for i in range(2,int(sqrt(N))+1):
while N % i == 0:
ret[i] += 1
N //= i
if N > 1:
ret[N] += 1
return ret
def PrimeFactorization2(N, L):
ret = defaultdict(int)
for p in L:
while N % p == 0:
ret[p] += 1
N //= p
return ret
mod = 10**8+9
Q = int(input())
for _ in range(Q):
seed,N,K,B = map(int,input().split())
X = [seed]
for i in range(N):
X.append(((X[i] * X[i]) + (X[i] * 12345)) % mod + 1)
BP = PrimeFactorization1(B)
L = list(BP.keys())
XP = []
for i in range(N+1):
XP.append(PrimeFactorization2(X[i], L))
ans = 1<<64
for p in L:
P = []
for i in range(N+1):
P.append(XP[i][p])
P.sort()
cnt = 0
for i in range(K):
cnt += P[i]
ans = min(ans, cnt // BP[p])
print(ans)
tnodino