結果

問題 No.1464 Number Conversion
ユーザー paruf4paruf4
提出日時 2021-04-10 16:59:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,039 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 75,660 KB
最終ジャッジ日時 2023-09-08 12:50:38
合計ジャッジ時間 4,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,004 KB
testcase_01 AC 75 ms
71,112 KB
testcase_02 AC 81 ms
75,328 KB
testcase_03 AC 77 ms
71,092 KB
testcase_04 AC 76 ms
71,500 KB
testcase_05 AC 74 ms
71,484 KB
testcase_06 AC 74 ms
71,508 KB
testcase_07 AC 76 ms
75,240 KB
testcase_08 AC 81 ms
75,296 KB
testcase_09 AC 77 ms
75,020 KB
testcase_10 AC 77 ms
75,108 KB
testcase_11 AC 78 ms
75,172 KB
testcase_12 AC 75 ms
71,496 KB
testcase_13 AC 77 ms
75,364 KB
testcase_14 AC 77 ms
75,624 KB
testcase_15 AC 77 ms
75,180 KB
testcase_16 AC 76 ms
75,516 KB
testcase_17 AC 78 ms
75,304 KB
testcase_18 AC 83 ms
75,024 KB
testcase_19 AC 77 ms
75,180 KB
testcase_20 AC 80 ms
75,112 KB
testcase_21 AC 73 ms
71,436 KB
testcase_22 AC 127 ms
75,412 KB
testcase_23 AC 75 ms
71,196 KB
testcase_24 AC 127 ms
75,260 KB
testcase_25 AC 127 ms
75,380 KB
testcase_26 AC 127 ms
75,660 KB
testcase_27 AC 74 ms
71,484 KB
testcase_28 AC 74 ms
71,100 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 = ""

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)

if ch == 0:
    print("0/1")
    exit(0)

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