結果

問題 No.1464 Number Conversion
ユーザー nephrologistnephrologist
提出日時 2021-04-02 22:12:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 87,380 KB
実行使用メモリ 76,036 KB
最終ジャッジ日時 2023-08-25 12:24:53
合計ジャッジ時間 3,927 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,756 KB
testcase_01 WA -
testcase_02 AC 77 ms
75,868 KB
testcase_03 AC 69 ms
71,396 KB
testcase_04 AC 68 ms
71,896 KB
testcase_05 AC 67 ms
72,000 KB
testcase_06 AC 70 ms
71,996 KB
testcase_07 AC 72 ms
75,588 KB
testcase_08 AC 72 ms
75,780 KB
testcase_09 AC 71 ms
75,860 KB
testcase_10 AC 72 ms
75,864 KB
testcase_11 AC 72 ms
75,760 KB
testcase_12 AC 70 ms
71,488 KB
testcase_13 AC 72 ms
75,588 KB
testcase_14 AC 72 ms
76,008 KB
testcase_15 AC 70 ms
75,880 KB
testcase_16 AC 70 ms
75,860 KB
testcase_17 AC 74 ms
75,872 KB
testcase_18 AC 77 ms
75,656 KB
testcase_19 AC 72 ms
76,036 KB
testcase_20 AC 72 ms
75,836 KB
testcase_21 AC 70 ms
72,000 KB
testcase_22 AC 118 ms
75,972 KB
testcase_23 AC 70 ms
71,876 KB
testcase_24 AC 116 ms
75,780 KB
testcase_25 AC 118 ms
75,856 KB
testcase_26 AC 116 ms
75,752 KB
testcase_27 AC 69 ms
71,824 KB
testcase_28 AC 68 ms
71,720 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"{bunshi}/{bunbo}")
0