結果

問題 No.2066 Simple Math !
ユーザー lilictakalilictaka
提出日時 2022-09-16 10:47:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 689 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 86,632 KB
実行使用メモリ 78,504 KB
最終ジャッジ日時 2023-08-23 05:53:49
合計ジャッジ時間 24,667 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,436 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 859 ms
77,844 KB
testcase_05 AC 857 ms
77,968 KB
testcase_06 AC 859 ms
78,376 KB
testcase_07 AC 862 ms
78,484 KB
testcase_08 AC 859 ms
78,188 KB
testcase_09 AC 854 ms
78,156 KB
testcase_10 AC 855 ms
77,984 KB
testcase_11 AC 857 ms
78,140 KB
testcase_12 AC 853 ms
78,304 KB
testcase_13 AC 863 ms
77,920 KB
testcase_14 AC 758 ms
77,712 KB
testcase_15 AC 753 ms
77,832 KB
testcase_16 AC 762 ms
77,780 KB
testcase_17 AC 755 ms
77,712 KB
testcase_18 AC 759 ms
77,760 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 903 ms
78,252 KB
testcase_25 AC 891 ms
78,504 KB
testcase_26 AC 899 ms
78,400 KB
testcase_27 AC 936 ms
78,388 KB
testcase_28 AC 895 ms
78,496 KB
testcase_29 AC 232 ms
77,588 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
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
T = int(input())
for _ in range(T):
    P,Q,K=map(int,input().split())
    ok = 10 ** 18
    ng = 0
    def isok(z):
        r = z//P
        if floor_sum(r+1,Q,P,Q+z-P*r)-1>= K:
            return True
        else:
            return False
    while ok -ng > 1:
        z = (ok+ng)>>1
        if isok(z):
            ok = z
        else:
            ng = z
    print(ok)
    
0