結果

問題 No.1339 循環小数
ユーザー GER_chenGER_chen
提出日時 2021-01-22 15:53:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,273 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 9,324 KB
最終ジャッジ日時 2023-08-27 06:29:18
合計ジャッジ時間 4,271 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,080 KB
testcase_01 AC 32 ms
9,124 KB
testcase_02 AC 33 ms
9,168 KB
testcase_03 AC 33 ms
9,108 KB
testcase_04 AC 33 ms
9,072 KB
testcase_05 AC 33 ms
9,124 KB
testcase_06 AC 33 ms
9,096 KB
testcase_07 AC 33 ms
9,216 KB
testcase_08 AC 32 ms
9,072 KB
testcase_09 AC 33 ms
9,192 KB
testcase_10 AC 33 ms
9,072 KB
testcase_11 AC 36 ms
9,060 KB
testcase_12 AC 36 ms
9,112 KB
testcase_13 AC 36 ms
9,072 KB
testcase_14 AC 36 ms
9,168 KB
testcase_15 AC 35 ms
9,108 KB
testcase_16 AC 35 ms
9,208 KB
testcase_17 AC 36 ms
9,168 KB
testcase_18 AC 35 ms
9,072 KB
testcase_19 AC 36 ms
9,252 KB
testcase_20 AC 36 ms
9,204 KB
testcase_21 AC 73 ms
9,144 KB
testcase_22 AC 73 ms
9,088 KB
testcase_23 AC 74 ms
9,316 KB
testcase_24 AC 72 ms
9,092 KB
testcase_25 AC 75 ms
9,284 KB
testcase_26 AC 72 ms
9,236 KB
testcase_27 AC 76 ms
9,236 KB
testcase_28 AC 71 ms
9,300 KB
testcase_29 AC 71 ms
9,324 KB
testcase_30 AC 67 ms
9,148 KB
testcase_31 AC 115 ms
9,292 KB
testcase_32 AC 118 ms
9,176 KB
testcase_33 AC 78 ms
9,292 KB
testcase_34 AC 39 ms
9,072 KB
testcase_35 AC 95 ms
9,052 KB
testcase_36 AC 76 ms
9,168 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
    if N == 1:
        print(1)
    for d in divlist(euler(N)):
        if pow(10, d, N) == 1:
            print(d)
            break
0