結果
| 問題 | No.28 末尾最適化 |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2021-11-18 05:26:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 862 bytes |
| コンパイル時間 | 468 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 101,504 KB |
| 最終ジャッジ日時 | 2024-12-24 21:12:31 |
| 合計ジャッジ時間 | 5,732 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 1 |
ソースコード
# 素因数分解
import math
def fac(x):
L=int(math.sqrt(x))
FACT=dict()
for i in range(2,L+2):
while x%i==0:
FACT[i]=FACT.get(i,0)+1
x=x//i
if x!=1:
FACT[x]=FACT.get(x,0)+1
return FACT
def calc(NOW,B):
A=0
while NOW%B==0:
NOW//=B
A+=1
return A
Q=int(input())
for tests in range(Q):
seed,N,K,B=map(int,input().split())
FAC=fac(B)
NOW=seed
X=[math.gcd(seed,B)]
for i in range(N):
NOW=1+(NOW*NOW+NOW*12345)%100000009
X.append(math.gcd(NOW,B))
ANS=1<<60
for f in FAC:
X.sort(key=lambda x:calc(x,f))
AX=0
NOW=1
for j in range(K):
NOW*=X[j]
while NOW%B==0:
NOW//=B
AX+=1
ANS=min(ANS,AX)
print(ANS)
titia