結果

問題 No.28 末尾最適化
ユーザー titiatitia
提出日時 2021-11-18 05:26:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 100,476 KB
最終ジャッジ日時 2023-08-26 06:07:01
合計ジャッジ時間 5,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
76,244 KB
testcase_01 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 素因数分解
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)
    
0