結果
| 問題 |
No.1936 Rational Approximation
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2022-05-13 22:15:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 450 bytes |
| コンパイル時間 | 411 ms |
| コンパイル使用メモリ | 82,408 KB |
| 実行使用メモリ | 96,796 KB |
| 最終ジャッジ日時 | 2024-07-22 02:13:17 |
| 合計ジャッジ時間 | 4,292 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | WA * 2 TLE * 1 -- * 11 |
ソースコード
from fractions import Fraction
p, q = map(int, input().split())
r = Fraction(p, q)
fmn = Fraction(1)
y = 1
while y <= q:
x = y * p // q + 1
f = Fraction(x, y)
if f < fmn:
fmn = f
y = (q * x + p - 1) // p
fmx = 0
y = 1
while y <= q:
x = (y * p - 1) // q
f = Fraction(x, y)
if f > fmx:
fmx = f
y = q * (x + 1) // p + 1
ans = fmn.numerator + fmn.denominator + fmx.numerator + fmx.denominator
print(ans)
Kude