結果

問題 No.1464 Number Conversion
ユーザー lloyz
提出日時 2022-06-05 01:08:17
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 321 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-09-21 03:54:04
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

s = input()
if '.' not in s:
    print(f"{s}/1")
    exit()
for i in range(len(s)):
    if s[i] == '.':
        idx = i
        break
digit = len(s) - idx - 1
a, b = map(int, s.split('.'))

a = a * pow(10, digit) + b
b = pow(10, digit)
gcd_ab = gcd(a, b)
a //= gcd_ab
b //= gcd_ab
print(f"{a}/{b}")
0