結果

問題 No.25 有限小数
ユーザー konchanksu
提出日時 2020-05-01 20:02:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-12-24 17:28:09
合計ジャッジ時間 1,912 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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):
    if not (tmp := n % m):
        return m
    else:
        return prime(m, tmp)
    
if N % M == 0:
    ans = N // M
    while not ans % 10:
        ans //= 10
    ans %= 10
else:
    N, M = N // (tmp := prime(N, M)), M // tmp
    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