結果

問題 No.1339 循環小数
ユーザー GER_chenGER_chen
提出日時 2021-01-22 15:50:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 11,140 KB
実行使用メモリ 9,304 KB
最終ジャッジ日時 2023-08-27 06:26:38
合計ジャッジ時間 3,721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,184 KB
testcase_01 AC 33 ms
9,132 KB
testcase_02 AC 34 ms
9,184 KB
testcase_03 AC 32 ms
9,064 KB
testcase_04 AC 32 ms
9,208 KB
testcase_05 AC 32 ms
9,216 KB
testcase_06 AC 32 ms
9,072 KB
testcase_07 AC 32 ms
9,112 KB
testcase_08 AC 32 ms
8,992 KB
testcase_09 AC 32 ms
9,152 KB
testcase_10 AC 33 ms
9,080 KB
testcase_11 AC 36 ms
9,128 KB
testcase_12 AC 36 ms
9,076 KB
testcase_13 AC 36 ms
9,212 KB
testcase_14 AC 36 ms
9,184 KB
testcase_15 AC 35 ms
9,224 KB
testcase_16 AC 35 ms
9,200 KB
testcase_17 AC 35 ms
9,068 KB
testcase_18 AC 35 ms
9,132 KB
testcase_19 AC 35 ms
9,132 KB
testcase_20 AC 36 ms
9,068 KB
testcase_21 AC 73 ms
9,228 KB
testcase_22 AC 72 ms
9,304 KB
testcase_23 AC 73 ms
9,204 KB
testcase_24 AC 72 ms
9,300 KB
testcase_25 AC 75 ms
9,284 KB
testcase_26 AC 72 ms
9,136 KB
testcase_27 AC 76 ms
9,136 KB
testcase_28 AC 71 ms
9,244 KB
testcase_29 AC 70 ms
9,256 KB
testcase_30 AC 66 ms
9,256 KB
testcase_31 AC 114 ms
9,204 KB
testcase_32 AC 118 ms
9,164 KB
testcase_33 AC 77 ms
9,136 KB
testcase_34 AC 39 ms
9,180 KB
testcase_35 AC 95 ms
9,076 KB
testcase_36 AC 76 ms
9,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki-1339
T = int(input())

candidates = [2*i+1 for i in range(1, 15811)]
primelist = [2]
p = 3
while p**2 <= 31623:
    primelist.append(p)
    candidates = [c for c in candidates if c%p]
    p = candidates[0]
primelist += candidates
l = len(primelist)

def euler(n):
    """
    nが奇数の時
    """
    i = 1
    ans = n
    while i < l and primelist[i]**2 <= n:
        p = primelist[i]
        if not n%p:
            ans -= ans//p
            while not n%p:
                n //= p
        i += 1
    if n > 1:
        ans -= ans//n
    return ans

def divlist(n):
    from collections import defaultdict as ddt
    d = ddt(int)
    i = 0
    while primelist[i]**2 <= n:
        p = primelist[i]
        while not n%p:
            d[p] += 1
            n //= p
        i += 1
    if n > 1:
        d[n] += 1
    ans = {1}
    for k in d.keys():
        plus = set()
        for x in ans:
            for ex in range(d[k]):
                plus.add(x*k**(ex+1))
        ans |= plus
    return sorted(ans)

for _ in range(T):
    N = int(input())  #10**9以下
    while not N%2:
        N //= 2
    while not N%5:
        N //= 5
    ans = euler(N)
    if ans < 2:
        print(1)
    else:
        for d in divlist(ans):
            if pow(10, d, N) == 1:
                print(d)
                break
0