結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 198 ms
88,888 KB
testcase_01 AC 190 ms
88,884 KB
testcase_02 AC 204 ms
89,208 KB
testcase_03 WA -
testcase_04 AC 197 ms
89,428 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 203 ms
89,368 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 202 ms
89,312 KB
testcase_13 WA -
testcase_14 AC 193 ms
89,188 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(100):
    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(100):
    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