結果

問題 No.1339 循環小数
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-01-16 10:15:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 131,028 KB
最終ジャッジ日時 2023-08-18 06:38:57
合計ジャッジ時間 9,374 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,820 KB
testcase_01 AC 83 ms
76,044 KB
testcase_02 AC 82 ms
76,052 KB
testcase_03 AC 83 ms
76,104 KB
testcase_04 AC 82 ms
76,008 KB
testcase_05 AC 82 ms
76,168 KB
testcase_06 AC 82 ms
75,896 KB
testcase_07 AC 79 ms
76,100 KB
testcase_08 AC 80 ms
76,124 KB
testcase_09 AC 81 ms
75,800 KB
testcase_10 AC 79 ms
76,168 KB
testcase_11 AC 83 ms
76,528 KB
testcase_12 AC 83 ms
76,164 KB
testcase_13 AC 83 ms
76,164 KB
testcase_14 AC 83 ms
76,212 KB
testcase_15 AC 85 ms
76,308 KB
testcase_16 AC 85 ms
76,348 KB
testcase_17 AC 84 ms
76,368 KB
testcase_18 AC 85 ms
76,616 KB
testcase_19 AC 83 ms
76,432 KB
testcase_20 AC 83 ms
76,612 KB
testcase_21 AC 316 ms
110,760 KB
testcase_22 AC 347 ms
117,776 KB
testcase_23 AC 336 ms
116,780 KB
testcase_24 AC 318 ms
114,324 KB
testcase_25 AC 340 ms
115,300 KB
testcase_26 AC 341 ms
114,120 KB
testcase_27 AC 342 ms
115,428 KB
testcase_28 AC 351 ms
116,280 KB
testcase_29 AC 308 ms
112,716 KB
testcase_30 AC 319 ms
112,408 KB
testcase_31 AC 463 ms
130,024 KB
testcase_32 AC 469 ms
131,028 KB
testcase_33 AC 337 ms
112,228 KB
testcase_34 AC 236 ms
102,116 KB
testcase_35 AC 509 ms
130,796 KB
testcase_36 AC 328 ms
114,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def baby_step_giant_step(a,b,mod):
    a %= mod
    b %= mod
    l = int(mod**0.5)+1
    h = 1 if mod != 0 else 0
    dic = {}
    for i in range(l):
        if h == b and i != 0:
            return i
        dic[h*b%mod] = i
        h *= a
        h %= mod
    g = h
    for i in range(l):
        if g in dic:
            res = (i+1)*l-dic[g]
            if pow(a,res,mod) == b:
                return res
            else:
                return -1
        g *= h
        g %= mod
    return -1

t = int(input())
for _ in range(t):
    n = int(input())
    while n%2 == 0:
        n //= 2
    while n%5 == 0:
        n //= 5
    print(baby_step_giant_step(10,1,n))
0