結果

問題 No.25 有限小数
ユーザー szkhtsszkhts
提出日時 2022-12-18 08:48:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 791 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 12,868 KB
最終ジャッジ日時 2023-08-11 05:01:39
合計ジャッジ時間 14,340 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,264 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 16 ms
8,272 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 126 ms
8,488 KB
testcase_08 AC 16 ms
8,420 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2,720 ms
8,332 KB
testcase_12 AC 16 ms
8,296 KB
testcase_13 WA -
testcase_14 AC 24 ms
8,404 KB
testcase_15 AC 1,234 ms
8,360 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 #

import math

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def primes(m):
    max = math.floor(math.sqrt(m))
    nums = []
    for i in range(2, max):
        while m % i == 0:
            nums.append(i)
            m = m / i
    return nums

def isTerminate(p):
    setted = list(set(p))
    if 2 in setted:
        setted.remove(2)
    if 5 in setted:
        setted.remove(5)

    if len(setted) > 0:
        return False
    else:
        return True

n = int(input())
m = int(input())

g = gcd(n, m)

n = n // g
m = m // g

p = primes(m)

a = isTerminate(p)
if a:
    ans = n / m
    s_ans = str(ans)
    for i in range(len(s_ans) - 1, -1, -1):
        if s_ans[i] != '0' and s_ans[i] != '.':
            print(s_ans[i])
            break
else:
    print(-1)
0