結果

問題 No.25 有限小数
ユーザー imulanimulan
提出日時 2017-03-01 00:53:18
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 827 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 8,120 KB
最終ジャッジ日時 2023-10-13 22:18:18
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,000 KB
testcase_01 AC 18 ms
7,964 KB
testcase_02 AC 17 ms
7,948 KB
testcase_03 AC 16 ms
7,932 KB
testcase_04 AC 16 ms
7,948 KB
testcase_05 AC 16 ms
7,944 KB
testcase_06 AC 16 ms
7,872 KB
testcase_07 AC 16 ms
8,008 KB
testcase_08 AC 16 ms
7,976 KB
testcase_09 AC 16 ms
7,944 KB
testcase_10 AC 16 ms
7,944 KB
testcase_11 AC 16 ms
7,948 KB
testcase_12 AC 16 ms
8,120 KB
testcase_13 AC 16 ms
8,116 KB
testcase_14 AC 16 ms
7,952 KB
testcase_15 AC 16 ms
7,944 KB
testcase_16 AC 16 ms
7,872 KB
testcase_17 AC 16 ms
7,944 KB
testcase_18 AC 16 ms
8,012 KB
testcase_19 AC 16 ms
7,960 KB
testcase_20 AC 16 ms
7,976 KB
testcase_21 AC 16 ms
8,008 KB
testcase_22 AC 15 ms
7,944 KB
testcase_23 AC 16 ms
8,048 KB
testcase_24 AC 15 ms
8,000 KB
testcase_25 AC 16 ms
7,976 KB
testcase_26 AC 16 ms
7,944 KB
testcase_27 AC 16 ms
8,004 KB
testcase_28 AC 16 ms
7,932 KB
testcase_29 AC 16 ms
8,052 KB
testcase_30 AC 16 ms
7,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

LIM = 10**19

def main():
    n = int(input())
    m = int(input())

    g = math.gcd(n,m)
    n,m = n//g,m//g

    # 整数の時の処理
    if m == 1:
        while n%10 == 0:
            n //= 10
        return n%10

    p2 = []
    a = 2
    while a < LIM:
        p2.append(a)
        a *= 2

    p5 = []
    a = 5
    while a < LIM:
        p5.append(a)
        a *= 5

    # 分母チェック
    t_m = m
    for d in reversed(p2):
        if t_m % d == 0:
            t_m //= d
            break
    for d in reversed(p5):
        if t_m % d == 0:
            t_m //= d
            break

    if t_m != 1:
        return -1

    while True:
        while n < m:
            n *= 10
        q = n//m
        n -= q*m

        if n == 0:
            return q

if __name__ == '__main__':
    print(main())
0