結果

問題 No.25 有限小数
ユーザー konchanksukonchanksu
提出日時 2020-05-01 18:50:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 763 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 12,904 KB
最終ジャッジ日時 2023-08-26 01:30:20
合計ジャッジ時間 13,869 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,868 KB
testcase_01 AC 13 ms
7,760 KB
testcase_02 AC 13 ms
7,800 KB
testcase_03 AC 15 ms
7,784 KB
testcase_04 AC 14 ms
7,908 KB
testcase_05 AC 800 ms
7,740 KB
testcase_06 AC 15 ms
7,800 KB
testcase_07 AC 117 ms
7,788 KB
testcase_08 AC 14 ms
7,776 KB
testcase_09 AC 19 ms
7,812 KB
testcase_10 AC 1,662 ms
7,828 KB
testcase_11 AC 2,681 ms
7,856 KB
testcase_12 WA -
testcase_13 AC 17 ms
7,756 KB
testcase_14 AC 22 ms
7,764 KB
testcase_15 AC 1,208 ms
7,788 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = int(input()), int(input())

def to_and_five(num, lists=[]):
    if num == 1:
        return lists
    if num % 2 == 0:
        return to_and_five(num // 2, lists + [2])
    if num % 5 == 0:
        return to_and_five(num // 5, lists + [5])
    return False

def prime(n, m):
    for i in range(2, int(min(m, n) ** 0.5) + 1):
        if n % i == 0 and m % i == 0:
            return prime(n // i, m // i)
    return n, m

if N % M == 0:
    ans = N // M
    while not ans % 10:
        ans //= 10
else:
    N, M = prime(N, M)
    if (tmp := to_and_five(M)):
        N %= 10
        for i in tmp:
            if i == 5:
                N *= 2
            else:
                N *= 5
            N %= 10
        ans = N
    else:
        ans = -1
print(ans)
0