結果

問題 No.1936 Rational Approximation
ユーザー sotanishysotanishy
提出日時 2022-05-13 21:49:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 369 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 54,552 KB
最終ジャッジ日時 2024-07-22 01:31:58
合計ジャッジ時間 1,489 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys
input = sys.stdin.readline

P, Q = map(int, input().split())

def calc(p, q):
    while True:
        np, nq = p*Q+P*q, 2*q*Q
        g = gcd(np, nq)
        np //= g
        nq //= g
        if nq < Q:
            p, q = np, nq
        else:
            break
    return p, q


pl, ql = calc(1, Q)
pr, qr = calc(1, 1)
print(pl+ql+pr+qr)
0