結果

問題 No.1464 Number Conversion
ユーザー Theta
提出日時 2022-10-25 13:16:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 760 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-07-03 12:39:43
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(*numbers: int) -> int:
    if len(numbers) == 1:
        return numbers[0]
    if len(numbers) == 2:
        a, b = numbers
        if a < b:
            a, b = b, a

        while True:

            if a % b == 0:
                return b
            a, b = b, a % b

    first_gcd = gcd(*numbers[:2])
    return gcd(first_gcd, *numbers[2:])


def main():
    X = input()
    if X == "0":
        print("0/1")
        return

    if "." not in X:
        print(f"{X}/1")
        return

    X_int, X_float = X.split(".")
    X_child = int(X_int + X_float)
    X_parent = 10**len(X_float)

    gcd_num = gcd(X_child, X_parent)
    X_child //= gcd_num
    X_parent //= gcd_num
    print(f"{X_child}/{X_parent}")


if __name__ == "__main__":
    main()
0