結果

問題 No.1936 Rational Approximation
ユーザー siganaisiganai
提出日時 2022-05-13 22:44:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 714 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 79,424 KB
最終ジャッジ日時 2023-09-29 08:19:25
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
79,292 KB
testcase_01 AC 160 ms
79,228 KB
testcase_02 AC 154 ms
79,220 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 148 ms
79,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353

import sys
input=sys.stdin.readline
def is_ok1(x):
    return (p - (q * y)) * x > pl * q
def is_ok2(x):
    return (p - (q * y)) * x < pl * q
p,q=map(int,input().split())
y = p // q
pl = p - q * y - 1
pr = pl + 1
ok = q - 1
ng = 1
while ok - ng > 1:
    mid = (ng + ok) // 2
    if is_ok1(mid):
        ok = mid
    else:
        ng = mid
ql = ok
pl += ql * y
qr = q - 1
pr += qr * y
g1 = math.gcd(pl,ql)
pl //= g1
ql //= g1
g2 = math.gcd(pr,qr)
pr //= g2
qr //= g2
print(pl + ql + pr + qr)
0