結果

問題 No.25 有限小数
ユーザー tnodinotnodino
提出日時 2022-02-13 07:49:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 737 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 8,480 KB
最終ジャッジ日時 2023-09-11 15:18:39
合計ジャッジ時間 1,814 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,364 KB
testcase_01 AC 17 ms
8,308 KB
testcase_02 AC 18 ms
8,232 KB
testcase_03 AC 18 ms
8,448 KB
testcase_04 AC 18 ms
8,016 KB
testcase_05 AC 16 ms
8,108 KB
testcase_06 AC 17 ms
8,104 KB
testcase_07 AC 17 ms
8,228 KB
testcase_08 AC 16 ms
8,044 KB
testcase_09 AC 16 ms
8,156 KB
testcase_10 AC 17 ms
8,040 KB
testcase_11 AC 16 ms
8,392 KB
testcase_12 AC 16 ms
8,044 KB
testcase_13 AC 16 ms
8,008 KB
testcase_14 AC 17 ms
8,104 KB
testcase_15 AC 16 ms
8,272 KB
testcase_16 AC 17 ms
7,968 KB
testcase_17 AC 17 ms
8,008 KB
testcase_18 AC 17 ms
7,976 KB
testcase_19 AC 16 ms
8,292 KB
testcase_20 AC 17 ms
8,396 KB
testcase_21 AC 17 ms
8,456 KB
testcase_22 AC 16 ms
8,348 KB
testcase_23 AC 17 ms
8,272 KB
testcase_24 AC 16 ms
8,232 KB
testcase_25 AC 16 ms
8,292 KB
testcase_26 AC 17 ms
8,480 KB
testcase_27 AC 17 ms
8,296 KB
testcase_28 AC 17 ms
8,432 KB
testcase_29 AC 17 ms
8,436 KB
testcase_30 AC 17 ms
8,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0