結果

問題 No.2066 Simple Math !
ユーザー とりゐとりゐ
提出日時 2022-08-30 16:29:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 889 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 77,704 KB
最終ジャッジ日時 2024-04-27 15:40:01
合計ジャッジ時間 22,623 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,456 KB
testcase_01 AC 316 ms
77,080 KB
testcase_02 AC 374 ms
77,184 KB
testcase_03 AC 160 ms
77,024 KB
testcase_04 AC 889 ms
77,056 KB
testcase_05 AC 870 ms
77,364 KB
testcase_06 AC 862 ms
77,564 KB
testcase_07 AC 865 ms
77,132 KB
testcase_08 AC 869 ms
77,124 KB
testcase_09 AC 870 ms
77,388 KB
testcase_10 AC 868 ms
76,780 KB
testcase_11 AC 854 ms
77,252 KB
testcase_12 AC 865 ms
77,704 KB
testcase_13 AC 852 ms
77,316 KB
testcase_14 AC 755 ms
76,724 KB
testcase_15 AC 766 ms
77,060 KB
testcase_16 AC 781 ms
76,984 KB
testcase_17 AC 755 ms
76,780 KB
testcase_18 AC 775 ms
76,732 KB
testcase_19 AC 572 ms
77,408 KB
testcase_20 AC 575 ms
77,144 KB
testcase_21 AC 585 ms
76,824 KB
testcase_22 AC 580 ms
76,788 KB
testcase_23 AC 571 ms
77,224 KB
testcase_24 AC 754 ms
77,156 KB
testcase_25 AC 761 ms
77,036 KB
testcase_26 AC 748 ms
77,228 KB
testcase_27 AC 752 ms
76,616 KB
testcase_28 AC 741 ms
76,912 KB
testcase_29 AC 278 ms
76,964 KB
testcase_30 AC 163 ms
76,948 KB
testcase_31 AC 246 ms
76,876 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,10**18
  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