結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
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 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = pr = 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
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