結果

問題 No.1339 循環小数
ユーザー ygd.ygd.
提出日時 2021-01-16 00:04:16
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 1,278 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 77,052 KB
最終ジャッジ日時 2023-08-17 19:20:08
合計ジャッジ時間 6,040 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,604 KB
testcase_01 AC 83 ms
75,840 KB
testcase_02 AC 78 ms
75,940 KB
testcase_03 AC 80 ms
76,056 KB
testcase_04 AC 78 ms
75,768 KB
testcase_05 AC 81 ms
75,868 KB
testcase_06 AC 82 ms
75,584 KB
testcase_07 AC 81 ms
76,316 KB
testcase_08 AC 84 ms
75,908 KB
testcase_09 AC 85 ms
76,292 KB
testcase_10 AC 85 ms
76,096 KB
testcase_11 AC 88 ms
76,572 KB
testcase_12 AC 90 ms
76,560 KB
testcase_13 AC 90 ms
76,868 KB
testcase_14 AC 84 ms
76,424 KB
testcase_15 AC 84 ms
76,680 KB
testcase_16 AC 85 ms
77,052 KB
testcase_17 AC 85 ms
76,600 KB
testcase_18 AC 85 ms
76,888 KB
testcase_19 AC 85 ms
76,560 KB
testcase_20 AC 85 ms
76,760 KB
testcase_21 AC 135 ms
76,708 KB
testcase_22 AC 141 ms
76,680 KB
testcase_23 AC 138 ms
76,756 KB
testcase_24 AC 133 ms
76,592 KB
testcase_25 AC 139 ms
76,588 KB
testcase_26 AC 135 ms
76,520 KB
testcase_27 AC 141 ms
76,480 KB
testcase_28 AC 145 ms
76,568 KB
testcase_29 AC 136 ms
77,036 KB
testcase_30 AC 141 ms
76,704 KB
testcase_31 AC 176 ms
76,696 KB
testcase_32 AC 174 ms
76,476 KB
testcase_33 AC 147 ms
76,696 KB
testcase_34 AC 114 ms
76,692 KB
testcase_35 AC 159 ms
76,420 KB
testcase_36 AC 139 ms
76,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def factorization(n):
    arr = []
    temp = n
    if temp%2 == 0:
      cnt = 0
      while temp%2 == 0:
        cnt += 1
        temp//=2
      arr.append(2)
    for i in range(3, int(-(-n**0.5//1))+1,2):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)
 
    if temp!=1:
        arr.append(temp)
 
    return arr


def Euler_totient_function(n):
    L = factorization(n)
    ret = n
    for x in L:
        ret = ret*(x-1)//x
    return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

Case = int(input())
for _ in range(Case):
    N = int(input())
    while N%2 == 0:
        N //= 2
    while N%5 == 0:
        N //= 5
    #print(N)
    if N == 1:
      print(1)
      continue
    M = Euler_totient_function(N)
    #print(M)
    L = make_divisors(M)
    #print(L)
    for x in L:
        #print(x,pow(10,x-1) - 1%N,N)
        a = pow(10,x,N) - 1
        #print("A",a)
        if a == 0:
            print(x)
            break
0