結果

問題 No.1339 循環小数
ユーザー ygd.
提出日時 2021-01-16 00:04:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,278 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 62,976 KB
最終ジャッジ日時 2024-11-26 18:51:10
合計ジャッジ時間 4,195 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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