結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 199 ms
89,004 KB
testcase_01 AC 195 ms
89,068 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 195 ms
89,440 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 197 ms
89,464 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 192 ms
89,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ok = 0.0
ng = x
for i in range(60):
    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 = x
for i in range(60):
    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