結果

問題 No.1936 Rational Approximation
ユーザー 👑 tatyamtatyam
提出日時 2022-04-07 15:51:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 555 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 91,012 KB
最終ジャッジ日時 2023-08-18 17:55:48
合計ジャッジ時間 4,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 207 ms
90,468 KB
testcase_01 AC 205 ms
90,452 KB
testcase_02 AC 215 ms
90,444 KB
testcase_03 WA -
testcase_04 AC 214 ms
90,532 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 211 ms
90,700 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 211 ms
90,620 KB
testcase_13 WA -
testcase_14 AC 205 ms
90,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import *
P, Q = map(int, input().split())
x = P / Q
X = Fraction(P, Q)

ok = 0.0
ng = 1.0
for i in range(200):
    mid = (ok + ng) / 2
    if Fraction(mid).limit_denominator(Q - 1) < X:
        ok = mid
    else:
        ng = mid

L = Fraction(ok).limit_denominator(Q - 1)

ok = 1.0
ng = 0.0
for i in range(200):
    mid = (ok + ng) / 2
    if Fraction(mid).limit_denominator(Q - 1) > X:
        ok = mid
    else:
        ng = mid

R = Fraction(ok).limit_denominator(Q - 1)

print(L.numerator + L.denominator + R.numerator + R.denominator)
0