結果

問題 No.1339 循環小数
ユーザー GER_chenGER_chen
提出日時 2021-01-22 16:24:22
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,282 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 11,028 KB
実行使用メモリ 9,364 KB
最終ジャッジ日時 2023-08-27 07:00:15
合計ジャッジ時間 3,587 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,120 KB
testcase_01 AC 31 ms
9,148 KB
testcase_02 AC 31 ms
8,996 KB
testcase_03 AC 31 ms
9,260 KB
testcase_04 AC 31 ms
8,996 KB
testcase_05 AC 30 ms
9,260 KB
testcase_06 AC 31 ms
9,072 KB
testcase_07 AC 30 ms
9,072 KB
testcase_08 AC 29 ms
9,156 KB
testcase_09 AC 30 ms
9,140 KB
testcase_10 AC 29 ms
9,236 KB
testcase_11 AC 31 ms
9,156 KB
testcase_12 AC 32 ms
9,196 KB
testcase_13 AC 32 ms
9,072 KB
testcase_14 AC 32 ms
9,168 KB
testcase_15 AC 31 ms
9,056 KB
testcase_16 AC 31 ms
9,120 KB
testcase_17 AC 33 ms
9,096 KB
testcase_18 AC 33 ms
9,112 KB
testcase_19 AC 31 ms
9,068 KB
testcase_20 AC 33 ms
9,196 KB
testcase_21 AC 69 ms
9,248 KB
testcase_22 AC 67 ms
9,304 KB
testcase_23 AC 67 ms
9,280 KB
testcase_24 AC 69 ms
9,276 KB
testcase_25 AC 71 ms
9,276 KB
testcase_26 AC 68 ms
9,140 KB
testcase_27 AC 73 ms
9,348 KB
testcase_28 AC 68 ms
9,364 KB
testcase_29 AC 67 ms
9,188 KB
testcase_30 AC 65 ms
9,308 KB
testcase_31 AC 108 ms
9,364 KB
testcase_32 AC 115 ms
9,088 KB
testcase_33 AC 75 ms
9,248 KB
testcase_34 AC 35 ms
9,112 KB
testcase_35 AC 89 ms
9,068 KB
testcase_36 AC 72 ms
9,224 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 ediv(n):
    """
    nが奇数の時
    """
    t = 1
    from collections import defaultdict as ddt
    d = ddt(int)
    i = 1
    while i < l and primelist[i]**2 <= n:
        p = primelist[i]
        if not n%p:
            n //= p
            t *= p-1
            while not n%p:
                n //= p
                d[p] += 1
        i += 1
    if n > 1:
        t *= n-1
        
    j = 0
    while primelist[j]**2 <= t:
        q = primelist[j]
        while not t%q:
            d[q] += 1
            t //= q
        j += 1
    if t > 1:
        d[t] += 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 ediv(N):
        if pow(10, d, N) == 1:
            print(d)
            break
0