結果

問題 No.2066 Simple Math !
ユーザー とりゐとりゐ
提出日時 2022-09-02 13:52:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 752 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 77,680 KB
最終ジャッジ日時 2024-04-27 15:43:11
合計ジャッジ時間 17,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,508 KB
testcase_01 AC 150 ms
77,068 KB
testcase_02 AC 176 ms
77,148 KB
testcase_03 AC 105 ms
77,660 KB
testcase_04 AC 701 ms
77,164 KB
testcase_05 AC 700 ms
77,108 KB
testcase_06 AC 713 ms
77,388 KB
testcase_07 AC 724 ms
76,968 KB
testcase_08 AC 720 ms
77,236 KB
testcase_09 AC 726 ms
77,568 KB
testcase_10 AC 735 ms
77,292 KB
testcase_11 AC 733 ms
77,428 KB
testcase_12 AC 752 ms
77,580 KB
testcase_13 AC 735 ms
77,100 KB
testcase_14 AC 682 ms
77,160 KB
testcase_15 AC 697 ms
76,764 KB
testcase_16 AC 696 ms
76,972 KB
testcase_17 AC 703 ms
76,924 KB
testcase_18 AC 685 ms
77,196 KB
testcase_19 AC 330 ms
77,588 KB
testcase_20 AC 334 ms
77,276 KB
testcase_21 AC 343 ms
77,432 KB
testcase_22 AC 339 ms
77,368 KB
testcase_23 AC 332 ms
77,424 KB
testcase_24 AC 519 ms
77,560 KB
testcase_25 AC 521 ms
77,680 KB
testcase_26 AC 521 ms
77,600 KB
testcase_27 AC 515 ms
77,608 KB
testcase_28 AC 518 ms
77,536 KB
testcase_29 AC 220 ms
76,888 KB
testcase_30 AC 119 ms
77,624 KB
testcase_31 AC 221 ms
76,632 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

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

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