結果

問題 No.1339 循環小数
ユーザー convexineqconvexineq
提出日時 2021-01-15 21:43:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 490 ms / 2,000 ms
コード長 686 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 130,536 KB
最終ジャッジ日時 2023-08-17 16:34:11
合計ジャッジ時間 8,863 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,436 KB
testcase_01 AC 74 ms
75,772 KB
testcase_02 AC 75 ms
75,724 KB
testcase_03 AC 76 ms
75,672 KB
testcase_04 AC 72 ms
75,628 KB
testcase_05 AC 72 ms
75,684 KB
testcase_06 AC 74 ms
75,780 KB
testcase_07 AC 73 ms
75,612 KB
testcase_08 AC 74 ms
75,768 KB
testcase_09 AC 74 ms
75,764 KB
testcase_10 AC 74 ms
75,584 KB
testcase_11 AC 76 ms
76,076 KB
testcase_12 AC 77 ms
75,980 KB
testcase_13 AC 77 ms
75,948 KB
testcase_14 AC 76 ms
76,080 KB
testcase_15 AC 75 ms
76,160 KB
testcase_16 AC 78 ms
75,836 KB
testcase_17 AC 75 ms
76,356 KB
testcase_18 AC 74 ms
75,908 KB
testcase_19 AC 77 ms
76,396 KB
testcase_20 AC 77 ms
76,128 KB
testcase_21 AC 301 ms
111,216 KB
testcase_22 AC 343 ms
117,400 KB
testcase_23 AC 330 ms
116,508 KB
testcase_24 AC 315 ms
113,748 KB
testcase_25 AC 337 ms
114,724 KB
testcase_26 AC 333 ms
114,444 KB
testcase_27 AC 325 ms
115,360 KB
testcase_28 AC 334 ms
116,456 KB
testcase_29 AC 295 ms
112,788 KB
testcase_30 AC 311 ms
113,412 KB
testcase_31 AC 451 ms
129,512 KB
testcase_32 AC 460 ms
130,096 KB
testcase_33 AC 324 ms
112,004 KB
testcase_34 AC 220 ms
102,148 KB
testcase_35 AC 490 ms
130,536 KB
testcase_36 AC 316 ms
115,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def discrete_logarithm(a,b,MOD,permit0):
    a %= MOD; b %= MOD
    q = int(MOD**0.5)+2
    # baby-step
    h = 1 if MOD != 1 else 0 
    memo = {}
    for i in range(q):
        if h==b and (permit0 or i): return i
        memo[h*b%MOD] = i
        h = h*a%MOD
    # giant-step #ここに来た時 h = a^q
    g = h
    for i in range(q):
        if g in memo:
            res = (i+1)*q-memo[g]
            if pow(a,res,MOD) == b: return res
            else: return -1
        g = g*h%MOD
        
    return -1 #見つからない場合


T,*a = map(int,open(0).read().split())
for ai in a:
    while ai%2==0: ai//=2
    while ai%5==0: ai//=5
    print(discrete_logarithm(10,1,ai,0))
0