結果
問題 |
No.2066 Simple Math !
|
ユーザー |
![]() |
提出日時 | 2025-03-03 23:02:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,806 bytes |
コンパイル時間 | 419 ms |
コンパイル使用メモリ | 82,600 KB |
実行使用メモリ | 79,584 KB |
最終ジャッジ日時 | 2025-03-03 23:03:18 |
合計ジャッジ時間 | 27,292 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 WA * 25 |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 from math import gcd # px+qy<=N # y<=(N-px)/q # y<=(px+N-pq+p+q)/q def solve(): # sum((a*i+b)//m for i in range(n))が求まる # a,b>=0 m>=1 def floor_sum(n: int, m: int, a: int, b: int) -> int: ans = 0 while 1: if a >= m: ans += (n-1)*n*(a//m)//2 a %= m if b >= m: ans += n*(b//m) b %= m y_max = (a*n+b)//m x_max = y_max*m-b if y_max == 0: return ans ans += (n-(x_max+a-1)//a)*y_max n, m, a, b = y_max, a, m, (a-x_max%a)%a def ok(m): return floor_sum(q,q,p,m-p*q+p+q)>k def binary_search(l, r, minimize): if minimize: l -= 1 else: r += 1 while l+1 < r: m = (l+r)//2 if ok(m) ^ minimize: l = m else: r = m if minimize: return r return l p,q,k=LI() g=gcd(p,q) p//=g q//=g print(binary_search(0,10**18+10**9,True)*g) for _ in range(II()):solve()