結果

問題 No.25 有限小数
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-07-15 12:25:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 763 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 73,044 KB
最終ジャッジ日時 2023-10-15 03:17:38
合計ジャッジ時間 5,548 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
72,644 KB
testcase_01 AC 102 ms
72,760 KB
testcase_02 AC 101 ms
72,776 KB
testcase_03 AC 104 ms
72,748 KB
testcase_04 AC 103 ms
72,976 KB
testcase_05 AC 103 ms
72,640 KB
testcase_06 AC 105 ms
72,892 KB
testcase_07 AC 101 ms
72,700 KB
testcase_08 AC 97 ms
72,888 KB
testcase_09 AC 102 ms
72,856 KB
testcase_10 AC 103 ms
72,604 KB
testcase_11 AC 105 ms
72,804 KB
testcase_12 AC 105 ms
72,736 KB
testcase_13 AC 104 ms
72,664 KB
testcase_14 AC 103 ms
72,708 KB
testcase_15 AC 102 ms
72,664 KB
testcase_16 AC 102 ms
72,780 KB
testcase_17 AC 104 ms
72,656 KB
testcase_18 AC 103 ms
72,872 KB
testcase_19 AC 106 ms
72,652 KB
testcase_20 AC 103 ms
72,696 KB
testcase_21 AC 105 ms
72,956 KB
testcase_22 AC 107 ms
73,008 KB
testcase_23 AC 106 ms
73,044 KB
testcase_24 AC 105 ms
72,888 KB
testcase_25 AC 105 ms
72,852 KB
testcase_26 AC 103 ms
72,876 KB
testcase_27 AC 104 ms
72,868 KB
testcase_28 AC 104 ms
72,892 KB
testcase_29 AC 103 ms
72,648 KB
testcase_30 AC 105 ms
72,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N = int(input())
M = int(input())
X = Counter([])
Y = Counter([])
while N%5==0:
    N//=5
    X[5] += 1
while N%2==0:
    N//=2
    X[2] += 1    


while M%5==0:
    M//=5
    Y[5] += 1
while M%2==0:
    M//=2
    Y[2] += 1   

if M!=1:
    if N==M:
        print(1)
    else:
        print(-1)
    exit()

m = min(X[2],X[5])
X[2] -= m
X[5] -= m

m = min(Y[2],Y[5])
Y[2] -= m
Y[5] -= m

m = min(X[2],Y[2])
X[2] -= m
Y[2] -= m
m = min(X[5],Y[5])
X[5] -= m
Y[5] -= m

K = max(Y.values())
X[5] += K - Y[5]
X[2] += K - Y[2]
N *= pow(5,X[5])*pow(2,X[2])
S = str(N)
for s in S[::-1]:
    if s!='0':
        print(s)
        exit()
0