結果
| 問題 | 
                            No.28 末尾最適化
                             | 
                    
| コンテスト | |
| ユーザー | 
                             titia
                         | 
                    
| 提出日時 | 2021-11-18 05:32:59 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 923 bytes | 
| コンパイル時間 | 133 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 11,136 KB | 
| 最終ジャッジ日時 | 2024-12-24 21:25:23 | 
| 合計ジャッジ時間 | 6,583 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 1 TLE * 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
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<<60
    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)
    
            
            
            
        
            
titia