結果

問題 No.1339 循環小数
ユーザー GER_chenGER_chen
提出日時 2021-01-22 16:05:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,335 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 9,288 KB
最終ジャッジ日時 2023-08-27 06:38:50
合計ジャッジ時間 2,946 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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が奇数の時
    """
    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
            j = 0
            m = p-1
            while primelist[j]**2 <= m:
                q = primelist[j]
                while not m%p:
                    d[q] += 1
                    m //= q
                j += 1
            if m > 1:
                d[m] += 1
            while not n%p:
                n //= p
                d[p] += 1
        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 ediv(N):
        if pow(10, d, N) == 1:
            print(d)
            break
0