結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
tnodino
|
| 提出日時 | 2022-02-13 07:49:07 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 5,000 ms |
| コード長 | 737 bytes |
| コンパイル時間 | 321 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-06-29 05:26:16 |
| 合計ジャッジ時間 | 2,129 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
from math import gcd
def Fraction(A, B):
G = gcd(A, B)
return A // G, B // G
def PrimeFactorization(N):
ret = {}
ret[2] = ret[5] = 0
while N % 2 == 0:
ret[2] += 1
N //= 2
while N % 5 == 0:
ret[5] += 1
N //= 5
if N > 1:
print(-1)
exit()
return ret
def BinPower(x, k, mod = 10**9+7):
ret = 1
while k > 0:
if k & 1:
ret = ret * x % mod
x = x * x % mod
k >>= 1
return ret
mod = 10**6
N = int(input())
M = int(input())
N,M = Fraction(N, M)
P = PrimeFactorization(M)
N *= BinPower(5, max(0, P[2]-P[5]), mod)
N %= mod
N *= BinPower(2, max(0, P[5]-P[2]), mod)
N %= mod
while N % 10 == 0:
N //= 10
print(N % 10)
tnodino