結果

問題 No.1464 Number Conversion
ユーザー nephrologistnephrologist
提出日時 2021-04-02 22:14:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2023-08-25 12:27:03
合計ジャッジ時間 2,694 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,844 KB
testcase_01 WA -
testcase_02 AC 18 ms
7,840 KB
testcase_03 AC 16 ms
7,788 KB
testcase_04 AC 16 ms
7,860 KB
testcase_05 AC 16 ms
7,796 KB
testcase_06 AC 16 ms
7,832 KB
testcase_07 AC 18 ms
7,844 KB
testcase_08 AC 19 ms
7,860 KB
testcase_09 AC 18 ms
7,812 KB
testcase_10 AC 16 ms
7,972 KB
testcase_11 AC 16 ms
7,816 KB
testcase_12 AC 16 ms
7,892 KB
testcase_13 AC 18 ms
7,788 KB
testcase_14 AC 20 ms
7,868 KB
testcase_15 AC 16 ms
7,852 KB
testcase_16 AC 17 ms
7,824 KB
testcase_17 AC 20 ms
7,920 KB
testcase_18 AC 40 ms
7,748 KB
testcase_19 AC 20 ms
7,808 KB
testcase_20 AC 18 ms
7,840 KB
testcase_21 AC 16 ms
7,792 KB
testcase_22 AC 215 ms
7,752 KB
testcase_23 AC 16 ms
7,796 KB
testcase_24 AC 185 ms
7,860 KB
testcase_25 AC 218 ms
7,832 KB
testcase_26 AC 217 ms
7,752 KB
testcase_27 AC 16 ms
7,920 KB
testcase_28 AC 16 ms
7,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

x = input()
if "." in x:
    a, b = x.split(".")
    bunshi = 0
    bunbo = 0
    bunshi = int(a) * pow(10, len(b)) + int(b)
    bunbo = pow(10, len(b))
else:
    bunshi = int(x)
    bunbo = 1

# 素因数分解
def prime_factor(n):
    # (素因数, 数)のリストで出てくる
    d = {}
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
            n //= i
    if n != 1:
        if n in d:
            d[n] += 1
        else:
            d[n] = 1
    return d


a = prime_factor(bunbo)
b = prime_factor(bunshi)

for key in a.keys():
    if key in b:
        n1 = b[key]
        n2 = a[key]
        if n1 > n2:
            bunshi //= pow(key, n2)
            bunbo //= pow(key, n2)
        else:
            bunbo //= pow(key, n1)
            bunshi //= pow(key, n1)
print(f"{int(bunshi)}/{int(bunbo)}")
0