結果
問題 | No.28 末尾最適化 |
ユーザー | titia |
提出日時 | 2021-11-18 05:51:16 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,231 bytes |
コンパイル時間 | 241 ms |
コンパイル使用メモリ | 82,364 KB |
実行使用メモリ | 67,484 KB |
最終ジャッジ日時 | 2024-06-07 01:58:24 |
合計ジャッジ時間 | 809 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ソースコード
import sys input = sys.stdin.readline from operator import itemgetter FAC=[{}, {}, {2: 1}, {3: 1}, {2: 2}, {5: 1}, {2: 1, 3: 1}, {7: 1}, {2: 3}, {3: 2}, {2: 1, 5: 1}, {11: 1}, {2: 2, 3: 1}, {13: 1}, {2: 1, 7: 1}, {3: 1, 5: 1}, {2: 4}, {17: 1}, {2: 1, 3: 2}, {19: 1}, {2: 2, 5: 1}, {3: 1, 7: 1}, {2: 1, 11: 1}, {23: 1}, {2: 3, 3: 1}, {5: 2}, {2: 1, 13: 1}, {3: 3}, {2: 2, 7: 1}, {29: 1}, {2: 1, 3: 1, 5: 1}, {31: 1}, {2: 5}, {3: 1, 11: 1}, {2: 1, 17: 1}, {5: 1, 7: 1}, {2: 2, 3: 2}, {37: 1}, {2: 1, 19: 1}, {3: 1, 13: 1}] for x in range(2,40): FAC[x]=fac(x) def calc(NOW,x): A=0 while NOW%x==0: NOW//=x A+=1 return A Q=int(input()) for tests in range(Q): seed,N,K,B=map(int,input().split()) LIST=list(FAC[B]) LEN=len(LIST) NOW=seed X=[[0]*LEN for i in range(N+1)] for i in range(LEN): X[0][i]=calc(NOW,LIST[i]) for i in range(N): NOW=1+(NOW*NOW+NOW*12345)%100000009 for j in range(LEN): X[i+1][j]=calc(NOW,LIST[j]) ANS=1<<30 for i in range(LEN): X.sort(key=itemgetter(i)) Y=0 for j in range(K): Y+=X[j][i] ANS=min(ANS,Y//FAC[B][LIST[i]]) print(ANS)