結果

問題 No.25 有限小数
ユーザー kohei2019kohei2019
提出日時 2021-02-10 12:40:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 452 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 86,696 KB
実行使用メモリ 71,636 KB
最終ジャッジ日時 2023-09-22 06:30:12
合計ジャッジ時間 4,506 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,580 KB
testcase_01 AC 75 ms
71,076 KB
testcase_02 AC 75 ms
71,056 KB
testcase_03 AC 78 ms
71,356 KB
testcase_04 AC 79 ms
71,188 KB
testcase_05 AC 77 ms
71,636 KB
testcase_06 AC 77 ms
71,200 KB
testcase_07 AC 77 ms
71,352 KB
testcase_08 AC 77 ms
71,188 KB
testcase_09 AC 77 ms
71,116 KB
testcase_10 AC 79 ms
71,260 KB
testcase_11 AC 76 ms
71,312 KB
testcase_12 AC 77 ms
71,280 KB
testcase_13 AC 77 ms
71,264 KB
testcase_14 AC 77 ms
71,464 KB
testcase_15 AC 77 ms
71,428 KB
testcase_16 AC 77 ms
71,244 KB
testcase_17 AC 78 ms
71,240 KB
testcase_18 AC 76 ms
71,292 KB
testcase_19 AC 77 ms
71,380 KB
testcase_20 AC 78 ms
71,280 KB
testcase_21 AC 77 ms
71,424 KB
testcase_22 AC 77 ms
71,584 KB
testcase_23 AC 77 ms
71,232 KB
testcase_24 AC 76 ms
71,584 KB
testcase_25 AC 79 ms
71,232 KB
testcase_26 AC 75 ms
71,232 KB
testcase_27 AC 76 ms
71,276 KB
testcase_28 AC 76 ms
71,252 KB
testcase_29 AC 76 ms
71,440 KB
testcase_30 AC 76 ms
71,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys
N = int(input())
M = int(input())
gcd = math.gcd(N,M)
N1 = N//gcd
M1 = M//gcd
l2 = 0
while M1 % 2 == 0:
    l2 += 1
    M1 //= 2
l5 = 0
while M1 % 5 == 0:
    l5 += 1
    M1 //= 5
if M1 != 1:
    print(-1)
    sys.exit()
if l2 > l5:
    print(5)
elif l2 == l5:
    div = 10
    while N1%div == 0:
        N1 //= 10
    print(N1%10)
else:
    c5 = l5-l2
    while c5:
        N1 %= 5
        N1 *= 2
        c5 -= 1
    print(N1)
0