結果

問題 No.1339 循環小数
ユーザー GER_chenGER_chen
提出日時 2021-01-22 15:27:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 785 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 9,000 KB
最終ジャッジ日時 2023-08-27 06:03:45
合計ジャッジ時間 10,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
8,876 KB
testcase_01 AC 29 ms
8,880 KB
testcase_02 AC 29 ms
8,884 KB
testcase_03 AC 29 ms
8,872 KB
testcase_04 AC 29 ms
8,800 KB
testcase_05 AC 29 ms
8,800 KB
testcase_06 AC 29 ms
8,804 KB
testcase_07 AC 29 ms
8,800 KB
testcase_08 AC 29 ms
8,824 KB
testcase_09 AC 29 ms
8,816 KB
testcase_10 AC 29 ms
8,876 KB
testcase_11 AC 33 ms
8,880 KB
testcase_12 AC 33 ms
8,796 KB
testcase_13 AC 34 ms
8,792 KB
testcase_14 AC 34 ms
8,856 KB
testcase_15 AC 33 ms
8,996 KB
testcase_16 AC 33 ms
8,812 KB
testcase_17 AC 33 ms
8,808 KB
testcase_18 AC 32 ms
8,792 KB
testcase_19 AC 33 ms
8,792 KB
testcase_20 AC 34 ms
8,880 KB
testcase_21 AC 443 ms
8,820 KB
testcase_22 AC 489 ms
8,816 KB
testcase_23 AC 474 ms
8,796 KB
testcase_24 AC 441 ms
8,876 KB
testcase_25 AC 483 ms
8,880 KB
testcase_26 AC 468 ms
8,812 KB
testcase_27 AC 473 ms
8,812 KB
testcase_28 AC 484 ms
8,844 KB
testcase_29 AC 402 ms
8,884 KB
testcase_30 AC 440 ms
9,000 KB
testcase_31 AC 780 ms
8,796 KB
testcase_32 AC 785 ms
8,812 KB
testcase_33 AC 493 ms
8,876 KB
testcase_34 AC 261 ms
8,816 KB
testcase_35 AC 735 ms
8,796 KB
testcase_36 AC 471 ms
8,808 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):
    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):
    

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:
        fw, bw = [], []
        j = 1
        while j**2 <= ans:
            if not ans%j:
                fw.append(j)
                bw.append(ans//j)
            j += 1
        d = fw+bw[::-1]
        flag = 0
        i = 0
        while not flag:
            if pow(10, d[i], N) == 1:
                print(d[i])
                flag = 1
            i += 1
0