結果

問題 No.25 有限小数
ユーザー szkhtsszkhts
提出日時 2021-05-26 10:21:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-23 06:55:18
合計ジャッジ時間 1,875 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def main():
    N = int(input())
    M = int(input())
    g = gcd(N, M)
    N //= g
    M //= g
    M2 = 0
    M5 = 0

    if N % M == 0:
        N //= M
        while N % 10 == 0:
            N //= 10
            print(N)
    else:
        N %= M
        while M % 2 == 0:
            M //= 2
            M2 += 1
        while M % 5 == 0:
            M //= 5
            M5 += 1

        if M != 1:
            print(-1)
        else:
            while M2 < M5:
                M2 += 1
                N *= 2
                N %= 100000000
                while N % 10 == 0:
                    N //= 10

            while M2 > M5:
                M5 += 1
                N *= 5
                N %= 1000000000
                while N % 10 == 0:
                    N //= 10

            print(N)

if __name__ == '__main__':
    main()
0