結果

問題 No.1339 循環小数
ユーザー H20
提出日時 2021-01-15 23:40:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,095 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 123,904 KB
最終ジャッジ日時 2024-11-26 18:39:43
合計ジャッジ時間 109,919 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 1
other AC * 2 TLE * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import collections
#素因数分解
#collections.Counter(prime_factorize(N))で個数を取得

#最大公約数
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

T = int(input())
for i in range(T):
    N = int(input())
    P=prime_factorize(N)
    if 2 in P:
        P.remove(2)
    if 5 in P:
        P.remove(5)
    if len(P)==0:
        print(1)

    else:
        L=list(set(P))

        rep = []
        for l in L:
            temp = 9 % l
            cnt = 1
            while temp!=0:
                temp = (temp*10+9)%l
                cnt+=1
            rep.append(cnt)
        lc = 1
        for r in rep:
            lc = lcm(lc,r)
        temp = 1
        CP = collections.Counter(P)
        for k,v in CP.items():
            if v>=2:
                temp*=k**(v-1)

        print(lc*temp)
0