結果

問題 No.2066 Simple Math !
ユーザー kozykozy
提出日時 2022-09-02 23:07:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 701 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 86,760 KB
実行使用メモリ 80,452 KB
最終ジャッジ日時 2023-08-10 05:29:25
合計ジャッジ時間 17,257 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,128 KB
testcase_01 AC 147 ms
78,468 KB
testcase_02 AC 223 ms
78,208 KB
testcase_03 AC 142 ms
77,612 KB
testcase_04 AC 677 ms
78,232 KB
testcase_05 AC 669 ms
77,812 KB
testcase_06 AC 669 ms
77,988 KB
testcase_07 AC 676 ms
77,652 KB
testcase_08 AC 671 ms
77,688 KB
testcase_09 AC 691 ms
77,632 KB
testcase_10 AC 683 ms
77,708 KB
testcase_11 AC 685 ms
77,556 KB
testcase_12 AC 701 ms
77,596 KB
testcase_13 AC 698 ms
77,732 KB
testcase_14 AC 671 ms
77,968 KB
testcase_15 AC 667 ms
77,660 KB
testcase_16 AC 670 ms
77,692 KB
testcase_17 AC 664 ms
77,648 KB
testcase_18 AC 662 ms
77,660 KB
testcase_19 AC 400 ms
79,296 KB
testcase_20 AC 418 ms
80,364 KB
testcase_21 AC 404 ms
80,152 KB
testcase_22 AC 412 ms
80,452 KB
testcase_23 AC 389 ms
78,296 KB
testcase_24 AC 409 ms
78,764 KB
testcase_25 AC 413 ms
78,756 KB
testcase_26 AC 417 ms
78,852 KB
testcase_27 AC 417 ms
78,712 KB
testcase_28 AC 414 ms
77,672 KB
testcase_29 AC 189 ms
78,132 KB
testcase_30 AC 143 ms
77,676 KB
testcase_31 AC 221 ms
79,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def floor_sum(n, m, a, b):
    ans = 0
    while True:
        if a >= m or a < 0:
            ans += n * (n - 1) * (a // m) // 2
            a %= m
        if b >= m or b < 0:
            ans += n * (b // m)
            b %= m
        y_max = a * n + b
        if y_max < m: break
        n, b, m, a = y_max // m, y_max % m, a, m
    return ans
#sum i=0^n-1 (ai+b)//m

def f(N):
  s=N//P
  a=floor_sum(s+1,Q,-P,N)
  return a+s+1
T=int(input())
for _ in range(T):
  P,Q,K=map(int,input().split())
  K+=1
  #print(f(4))
  g=math.gcd(P,Q)
  P//=g
  Q//=g
  
  sita=0
  ue=P*Q-1
  flag=False
  for i in range(100):
    this=(sita+ue)//2
    if f(this)>=K:
      ue=this
    else:
      sita=this
    if (ue-sita)<=1:
      if f(sita)>=K:
        print(sita*g)
      elif f(ue)>=K:
        print(ue*g)
      else:
        flag=True
        break
      break
  if flag:
    k=f(P*Q-1)
    print((P*Q-1+K-k)*g)
0