結果

問題 No.1464 Number Conversion
コンテスト
ユーザー Theta
提出日時 2022-10-25 13:12:12
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 654 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 355 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-03-24 20:51:18
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 = float(input())
    if X == 0:
        print("0/1")
        return
    X_parent = int(1e8)
    X_child = int(X*X_parent)
    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