結果

問題 No.1339 循環小数
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-15 22:09:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,428 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 170,808 KB
最終ジャッジ日時 2023-08-17 17:21:11
合計ジャッジ時間 7,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

t = int(input())

import math

def is_prime(n):
    if n == 1:
        return False

    for i in range(2, int(math.sqrt(n))+1):
        if n%i == 0:
            return False

    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def factorize(n):
    d = {}
    temp = int(math.sqrt(n))+1
    for i in range(2, temp):
        while n%i== 0:
            n //= i
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    if d == {}:
        d[n] = 1
    else:
        if n in d:
            d[n] += 1
        elif n != 1:
            d[n] =1
    return d

def calc(x):
    if x == 2 or x == 5:
        return 1
    D = make_divisors(x-1)
    for d in D:
        if int('9'*d)%x == 0:
            res = d
            break
    return res


for _ in range(t):
    n = int(input())
    if is_prime(n):
        print(calc(n))
    else:
        F = factorize(n)
        #print(F)
        temp = []
        for k, _ in F.items():
            temp.append(calc(k))
        ans = lcm_list(temp)
        #print(temp)
        print(ans)
0