結果

問題 No.28 末尾最適化
ユーザー titiatitia
提出日時 2021-11-18 05:34:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 917 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 8,636 KB
最終ジャッジ日時 2023-08-26 06:19:05
合計ジャッジ時間 5,980 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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

FAC=[dict() for i in range(40)]

for x in range(2,40):
    FAC[x]=fac(x)

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())

    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<<30

    for f in FAC[B]:
        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