結果
問題 |
No.1936 Rational Approximation
|
ユーザー |
![]() |
提出日時 | 2022-05-13 22:43:33 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 707 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 65,968 KB |
最終ジャッジ日時 | 2024-07-22 02:53:15 |
合計ジャッジ時間 | 1,896 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 14 |
ソースコード
#!/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)