結果

問題 No.25 有限小数
ユーザー mizunomidori
提出日時 2016-07-02 03:13:53
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 590 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-15 21:16:52
合計ジャッジ時間 1,958 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)
N = int(input())
M = int(input())
d = gcd(N, M)
N //= d
M //= d
a2, a5 = 0, 0
while M % 2 == 0:
    a2 += 1
    M //= 2
while M % 5 == 0:
    a5 += 1
    M //= 5
if M != 1:
    print("-1")
else:
    while N % 10 == 0:
        N //= 10
    ret = N % 10
    for i in range(a2):
        ret = (ret * 10) // 2
        if ret % 10 == 0:
            ret /= 10
        ret = ret % 10
    for i in range(a5):
        ret = (ret * 10) // 5
        if ret % 10 == 0:
            ret //= 10
        ret = ret % 10
    print(ret)
0