結果

問題 No.1936 Rational Approximation
ユーザー siganaisiganai
提出日時 2022-05-13 22:17:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 778 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 79,476 KB
最終ジャッジ日時 2023-09-29 07:41:21
合計ジャッジ時間 3,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 144 ms
78,748 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 142 ms
78,844 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 - 1) > x * q
def is_ok2(x):
    return p * (q - 1) < x * q
p,q=map(int,input().split())
ql=qr=q-1
ok = 0
ng = 10 ** 9 + 5
while ng - ok > 1:
    mid = (ng + ok) // 2
    if is_ok1(mid):
        ok = mid
    else:
        ng = mid
pl = ok
ok = 10 ** 9 + 5
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