結果

問題 No.2066 Simple Math !
ユーザー とりゐとりゐ
提出日時 2022-08-02 20:33:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 627 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 78,256 KB
最終ジャッジ日時 2024-04-27 15:41:13
合計ジャッジ時間 9,075 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,876 KB
testcase_01 AC 200 ms
77,084 KB
testcase_02 AC 243 ms
77,068 KB
testcase_03 AC 124 ms
76,960 KB
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 -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 130 ms
77,020 KB
testcase_31 AC 166 ms
76,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def floor_sum(n,m,a,b):
  ans=0
  while True:
    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 calc(p,q,m):
  n=min(q,m//p+1)
  return floor_sum(n,q,p,q+m-p*(n-1))

import math
def solve():
  p,q,k=map(int,input().split())
  g=math.gcd(p,q)
  p//=g
  q//=g
  ng,ok=0,2*10**9+1
  while ok-ng>1:
    mid=(ok+ng)//2
    if calc(p,q,mid)>k:
      ok=mid
    else:
      ng=mid
  print(ok*g)

for _ in range(int(input())):
  solve()
0