結果

問題 No.1339 循環小数
ユーザー titiatitia
提出日時 2021-01-15 23:01:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,039 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 76,716 KB
最終ジャッジ日時 2023-08-17 18:16:40
合計ジャッジ時間 6,632 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,452 KB
testcase_01 AC 80 ms
75,960 KB
testcase_02 AC 81 ms
75,632 KB
testcase_03 AC 80 ms
75,440 KB
testcase_04 AC 81 ms
75,784 KB
testcase_05 AC 80 ms
76,012 KB
testcase_06 AC 87 ms
75,740 KB
testcase_07 AC 77 ms
75,804 KB
testcase_08 AC 81 ms
75,956 KB
testcase_09 AC 81 ms
75,688 KB
testcase_10 AC 80 ms
76,316 KB
testcase_11 AC 81 ms
76,456 KB
testcase_12 AC 89 ms
76,200 KB
testcase_13 AC 95 ms
76,716 KB
testcase_14 AC 87 ms
76,084 KB
testcase_15 AC 88 ms
76,248 KB
testcase_16 AC 88 ms
76,700 KB
testcase_17 AC 88 ms
76,384 KB
testcase_18 AC 86 ms
76,240 KB
testcase_19 AC 87 ms
76,676 KB
testcase_20 AC 83 ms
76,560 KB
testcase_21 AC 134 ms
76,248 KB
testcase_22 AC 142 ms
76,460 KB
testcase_23 AC 145 ms
76,620 KB
testcase_24 AC 135 ms
76,464 KB
testcase_25 AC 142 ms
76,560 KB
testcase_26 AC 143 ms
76,444 KB
testcase_27 AC 140 ms
76,452 KB
testcase_28 AC 142 ms
76,404 KB
testcase_29 AC 129 ms
76,244 KB
testcase_30 AC 135 ms
76,412 KB
testcase_31 AC 155 ms
76,432 KB
testcase_32 AC 160 ms
76,180 KB
testcase_33 AC 138 ms
76,500 KB
testcase_34 AC 111 ms
76,184 KB
testcase_35 AC 200 ms
75,940 KB
testcase_36 AC 140 ms
76,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

import math

def fac(x):
    L=int(math.sqrt(x))

    FACT=dict()

    for i in range(2,L+2):
        while x%i==0:
            FACT[i]=FACT.get(i,0)+1
            x=x//i

    if x!=1:
        FACT[x]=FACT.get(x,0)+1
    return FACT

def faclist(x):  
    xr=math.ceil(math.sqrt(x))

    LIST=[]
    for i in range(1,xr+1):
        if x%i==0:
            LIST.append(i)
            LIST.append(x//i)

    return sorted(set(LIST))

def calc(N):

    while N%2==0:
        N//=2

    while N%5==0:
        N//=5

    if N==1:
        return 1
    F=fac(N)
    ANS=1
    for f in F:
        for i in faclist(f-1):
            if pow(10,i,f)==1:
                xx=i
                break

        while True:
            if pow(10,xx,f**F[f])==1:
                ANS*=xx
                break
            else:
                xx*=f

    for i in faclist(ANS):
        if pow(10,i,N)==1:
            return i

T=int(input())
for tests in range(T):
    N=int(input())
    print(calc(N))

    

    
    
0