結果

問題 No.1464 Number Conversion
ユーザー nephrologistnephrologist
提出日時 2021-04-02 22:07:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 76,212 KB
最終ジャッジ日時 2023-08-25 12:20:48
合計ジャッジ時間 3,798 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,432 KB
testcase_01 WA -
testcase_02 AC 73 ms
75,764 KB
testcase_03 AC 69 ms
71,500 KB
testcase_04 AC 70 ms
71,752 KB
testcase_05 AC 70 ms
71,932 KB
testcase_06 AC 71 ms
71,752 KB
testcase_07 AC 75 ms
75,828 KB
testcase_08 AC 74 ms
75,592 KB
testcase_09 AC 73 ms
75,840 KB
testcase_10 AC 72 ms
76,056 KB
testcase_11 AC 73 ms
75,660 KB
testcase_12 AC 69 ms
71,868 KB
testcase_13 AC 73 ms
75,752 KB
testcase_14 AC 73 ms
75,796 KB
testcase_15 AC 72 ms
75,844 KB
testcase_16 AC 71 ms
75,956 KB
testcase_17 AC 72 ms
76,212 KB
testcase_18 AC 79 ms
75,760 KB
testcase_19 AC 73 ms
75,760 KB
testcase_20 AC 73 ms
75,764 KB
testcase_21 AC 70 ms
71,580 KB
testcase_22 AC 117 ms
75,764 KB
testcase_23 AC 70 ms
71,368 KB
testcase_24 AC 118 ms
75,780 KB
testcase_25 AC 116 ms
75,708 KB
testcase_26 AC 117 ms
75,808 KB
testcase_27 AC 70 ms
72,012 KB
testcase_28 AC 70 ms
71,576 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:
    print(x + "/1")
    exit()

# 素因数分解
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"{bunshi}/{bunbo}")
0