結果

問題 No.2066 Simple Math !
ユーザー とりゐとりゐ
提出日時 2022-08-02 20:33:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 782 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 78,128 KB
最終ジャッジ日時 2024-04-27 15:41:34
合計ジャッジ時間 19,518 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
54,700 KB
testcase_01 AC 265 ms
76,764 KB
testcase_02 AC 323 ms
76,752 KB
testcase_03 AC 138 ms
76,820 KB
testcase_04 AC 755 ms
78,004 KB
testcase_05 AC 769 ms
78,100 KB
testcase_06 AC 758 ms
78,028 KB
testcase_07 AC 753 ms
77,736 KB
testcase_08 AC 759 ms
77,836 KB
testcase_09 AC 782 ms
77,696 KB
testcase_10 AC 762 ms
77,564 KB
testcase_11 AC 768 ms
77,712 KB
testcase_12 AC 766 ms
77,816 KB
testcase_13 AC 756 ms
78,128 KB
testcase_14 AC 684 ms
76,788 KB
testcase_15 AC 681 ms
76,668 KB
testcase_16 AC 668 ms
76,712 KB
testcase_17 AC 691 ms
76,848 KB
testcase_18 AC 689 ms
76,880 KB
testcase_19 AC 507 ms
77,680 KB
testcase_20 AC 518 ms
77,408 KB
testcase_21 AC 506 ms
77,304 KB
testcase_22 AC 517 ms
77,304 KB
testcase_23 AC 501 ms
76,788 KB
testcase_24 AC 687 ms
77,012 KB
testcase_25 AC 685 ms
77,020 KB
testcase_26 AC 655 ms
77,036 KB
testcase_27 AC 661 ms
76,760 KB
testcase_28 AC 672 ms
76,776 KB
testcase_29 AC 232 ms
76,620 KB
testcase_30 AC 139 ms
76,508 KB
testcase_31 AC 208 ms
76,628 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,10**18
  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