結果

問題 No.1936 Rational Approximation
ユーザー siganaisiganai
提出日時 2022-05-13 23:05:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 86,740 KB
実行使用メモリ 79,244 KB
最終ジャッジ日時 2023-09-29 08:48:53
合計ジャッジ時間 4,701 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
79,060 KB
testcase_01 AC 147 ms
78,940 KB
testcase_02 AC 150 ms
78,972 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 151 ms
78,992 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 - 1) < q * x
p,q=map(int,input().split())
y = p // q
pl = p - q * y - 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
ok = p
ng = 0
while ok - ng > 1:
    mid = (ng + ok) // 2
    if is_ok2(mid):
        ok = mid
    else:
        ng = mid
pr = ok

g1 = math.gcd(pl,ql)
pl //= g1
ql //= g1
g2 = math.gcd(pr,qr)
pr //= g2
qr //= g2
print(pl + ql + pr + qr)
0