結果

問題 No.28 末尾最適化
ユーザー tnodinotnodino
提出日時 2022-02-13 15:41:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 946 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 16,348 KB
最終ジャッジ日時 2023-09-11 15:31:04
合計ジャッジ時間 6,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from math import sqrt
from collections import defaultdict
def PrimeFactorization1(N):
    ret = defaultdict(int)
    for i in range(2,int(sqrt(N))+1):
        while N % i == 0:
            ret[i] += 1
            N //= i
    if N > 1:
        ret[N] += 1
    return ret

def PrimeFactorization2(N, L):
    ret = defaultdict(int)
    for p in L:
        while N % p == 0:
            ret[p] += 1
            N //= p
    return ret

mod = 10**8+9
Q = int(input())
for _ in range(Q):
    seed,N,K,B = map(int,input().split())
    X = [seed]
    for i in range(N):
        X.append(((X[i] * X[i]) + (X[i] * 12345)) % mod + 1)
    BP = PrimeFactorization1(B)
    L = list(BP.keys())
    XP = []
    for i in range(N+1):
        XP.append(PrimeFactorization2(X[i], L))
    ans = 1<<64
    for p in L:
        P = []
        for i in range(N+1):
            P.append(XP[i][p])
        P.sort()
        ans = min(ans, sum(P[:K]) // BP[p])
    print(ans)
0