結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
ayaoni
|
| 提出日時 | 2020-12-04 13:06:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 5,000 ms |
| コード長 | 895 bytes |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 81,788 KB |
| 実行使用メモリ | 54,024 KB |
| 最終ジャッジ日時 | 2024-09-14 23:04:42 |
| 合計ジャッジ時間 | 2,756 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
import sys
from math import gcd
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
N,M = I(),I()
g = gcd(N,M)
N //= g
M //= g
X = M
a,b = 0,0
while X % 2 == 0:
X //= 2
a += 1
while X % 5 == 0:
X //= 5
b += 1
if X != 1:
print(-1)
else:
if a == b == 0:
while N % 10 == 0:
N //= 10
print(N % 10)
else:
ans = N % 10
if a < b:
ans *= pow(2,b-a,10)
elif a > b:
ans *= pow(5,a-b,10)
print(ans % 10)
ayaoni