結果

問題 No.25 有限小数
ユーザー tnodinotnodino
提出日時 2022-02-13 07:46:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 817 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 13,256 KB
最終ジャッジ日時 2023-09-11 15:18:35
合計ジャッジ時間 11,928 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,612 KB
testcase_01 AC 20 ms
8,780 KB
testcase_02 AC 19 ms
8,764 KB
testcase_03 AC 19 ms
8,768 KB
testcase_04 AC 23 ms
8,732 KB
testcase_05 AC 542 ms
8,764 KB
testcase_06 AC 20 ms
8,648 KB
testcase_07 AC 88 ms
8,652 KB
testcase_08 AC 19 ms
8,628 KB
testcase_09 AC 24 ms
8,780 KB
testcase_10 AC 1,181 ms
8,820 KB
testcase_11 AC 1,735 ms
8,616 KB
testcase_12 AC 20 ms
8,780 KB
testcase_13 AC 22 ms
8,784 KB
testcase_14 AC 25 ms
8,612 KB
testcase_15 AC 792 ms
8,780 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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