結果

問題 No.1464 Number Conversion
ユーザー paruf4paruf4
提出日時 2021-04-10 16:55:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,016 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 75,892 KB
最終ジャッジ日時 2023-09-08 12:46:37
合計ジャッジ時間 3,877 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,216 KB
testcase_01 WA -
testcase_02 AC 76 ms
75,636 KB
testcase_03 AC 73 ms
71,136 KB
testcase_04 AC 73 ms
71,552 KB
testcase_05 AC 71 ms
71,328 KB
testcase_06 AC 74 ms
71,868 KB
testcase_07 AC 76 ms
75,516 KB
testcase_08 AC 78 ms
75,692 KB
testcase_09 AC 75 ms
75,712 KB
testcase_10 AC 73 ms
75,684 KB
testcase_11 AC 75 ms
75,616 KB
testcase_12 AC 71 ms
71,768 KB
testcase_13 AC 76 ms
75,608 KB
testcase_14 AC 75 ms
75,836 KB
testcase_15 AC 76 ms
75,892 KB
testcase_16 AC 75 ms
75,724 KB
testcase_17 AC 77 ms
75,812 KB
testcase_18 AC 82 ms
75,860 KB
testcase_19 AC 77 ms
75,808 KB
testcase_20 AC 77 ms
75,696 KB
testcase_21 AC 72 ms
71,628 KB
testcase_22 AC 124 ms
75,612 KB
testcase_23 AC 73 ms
71,080 KB
testcase_24 AC 124 ms
75,524 KB
testcase_25 AC 124 ms
75,580 KB
testcase_26 AC 126 ms
75,672 KB
testcase_27 AC 70 ms
71,640 KB
testcase_28 AC 71 ms
71,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def factorization(n):
    retlist = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            retlist.append([i, cnt])

    if tmp != 1:
        retlist.append([tmp, 1])

    if retlist == []:
        retlist.append([n, 1])

    return retlist


s = input()
a = ""
b = ""
# print(s.find("."))
if s.find(".") != -1:
    a, b = s.split(".")
else:
    print(s+"/1")
    exit(0)

d = len(b)
ch = ""
f = False
for bb in b:
    if bb != "0":
        f = True
    if f:
        ch += bb
if ch == "":
    ch = 0
else:
    ch = int(ch)

ch += int(a)*(10**d)
dch = factorization(ch)
dmo = factorization(10**d)
div = []
for num_ch, val_ch in dch:
    for num_mo, val_mo in dmo:
        if num_ch == num_mo:
            div.append((num_ch, min(val_ch, val_mo)))
mo = 10**d
# ch = int(ch)+int(a)*(10**d)
for dn, dv in div:
    mo //= dn**dv
    ch //= dn**dv

print(str(ch)+"/"+str(mo))
0