結果

問題 No.1339 循環小数
ユーザー FuyuruFuyuru
提出日時 2023-11-09 15:41:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 489 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 129,504 KB
最終ジャッジ日時 2023-11-09 15:41:41
合計ジャッジ時間 8,000 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,588 KB
testcase_01 AC 43 ms
59,732 KB
testcase_02 AC 44 ms
59,732 KB
testcase_03 AC 43 ms
59,732 KB
testcase_04 AC 43 ms
59,732 KB
testcase_05 AC 47 ms
59,732 KB
testcase_06 AC 43 ms
59,732 KB
testcase_07 AC 43 ms
59,732 KB
testcase_08 AC 44 ms
59,732 KB
testcase_09 AC 54 ms
59,732 KB
testcase_10 AC 43 ms
59,732 KB
testcase_11 AC 47 ms
61,868 KB
testcase_12 AC 48 ms
61,868 KB
testcase_13 AC 46 ms
61,868 KB
testcase_14 AC 47 ms
61,852 KB
testcase_15 AC 46 ms
61,868 KB
testcase_16 AC 46 ms
61,852 KB
testcase_17 AC 46 ms
61,852 KB
testcase_18 AC 46 ms
61,868 KB
testcase_19 AC 46 ms
61,868 KB
testcase_20 AC 46 ms
61,852 KB
testcase_21 AC 275 ms
109,948 KB
testcase_22 AC 335 ms
115,960 KB
testcase_23 AC 297 ms
114,640 KB
testcase_24 AC 280 ms
112,072 KB
testcase_25 AC 297 ms
112,404 KB
testcase_26 AC 322 ms
112,488 KB
testcase_27 AC 291 ms
111,916 KB
testcase_28 AC 307 ms
116,116 KB
testcase_29 AC 260 ms
111,700 KB
testcase_30 AC 305 ms
109,592 KB
testcase_31 AC 428 ms
128,944 KB
testcase_32 AC 422 ms
129,504 KB
testcase_33 AC 334 ms
111,544 KB
testcase_34 AC 193 ms
98,764 KB
testcase_35 AC 489 ms
129,496 KB
testcase_36 AC 291 ms
113,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


def discrete_log(x,y,M):
    m = math.ceil(math.sqrt(M))
    pows = dict()
    p = 1
    for i in range(m):
        if p not in pows:
            pows[p] = i
        p = p*x%M
    inv = pow(x,m*(-1),M)
    tmp = y%M
    for i in range(m):
        if tmp in pows:
            return i*m+pows[tmp]
        tmp = tmp*inv%M
        
        
def get_length(d):
    while d%2 == 0:
        d //= 2
    while d%5 == 0:
        d //= 5
    if d == 1:
        return 1
    return discrete_log(10,pow(10,-1,d),d)+1


T = int(input())
for i in range(T):
    N = int(input())
    print(get_length(N))
0