結果

問題 No.25 有限小数
ユーザー tnodino
提出日時 2022-02-13 07:46:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 817 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-29 05:26:13
合計ジャッジ時間 12,770 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import gcd, sqrt
def Fraction(A, B):
    G = gcd(A, B)
    return A // G, B // G

def PrimeFactorization(N):
    ret = defaultdict(int)
    for i in range(2,int(sqrt(N))+1):
        while N % i == 0:
            ret[i] += 1
            N //= i
    if N > 1:
        ret[N] += 1
    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)
for i in P.keys():
    if i != 2 and i != 5:
        print(-1)
        exit()
N *= BinPower(5, max(0, P[2]-P[5]), mod)
N *= BinPower(2, max(0, P[5]-P[2]), mod)
N %= mod
while N % 10 == 0:
    N //= 10
print(N % 10)
0