結果

問題 No.1339 循環小数
ユーザー GER_chenGER_chen
提出日時 2021-01-22 15:20:07
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
実行時間 -
コード長 1,076 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 17,404 KB
最終ジャッジ日時 2023-08-27 05:54:50
合計ジャッジ時間 4,119 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

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

def euler(n):
    i = 1
    ans = n
    while 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