結果

問題 No.2066 Simple Math !
ユーザー kozykozy
提出日時 2022-09-02 23:07:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 587 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,524 KB
実行使用メモリ 79,176 KB
最終ジャッジ日時 2024-04-27 22:47:19
合計ジャッジ時間 13,905 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
52,528 KB
testcase_01 AC 101 ms
76,968 KB
testcase_02 AC 168 ms
77,588 KB
testcase_03 AC 108 ms
76,844 KB
testcase_04 AC 567 ms
76,560 KB
testcase_05 AC 559 ms
76,512 KB
testcase_06 AC 574 ms
76,872 KB
testcase_07 AC 584 ms
76,688 KB
testcase_08 AC 573 ms
76,624 KB
testcase_09 AC 584 ms
76,628 KB
testcase_10 AC 587 ms
76,952 KB
testcase_11 AC 570 ms
76,768 KB
testcase_12 AC 583 ms
76,648 KB
testcase_13 AC 579 ms
76,728 KB
testcase_14 AC 552 ms
76,520 KB
testcase_15 AC 554 ms
76,832 KB
testcase_16 AC 558 ms
76,744 KB
testcase_17 AC 553 ms
77,104 KB
testcase_18 AC 554 ms
76,672 KB
testcase_19 AC 333 ms
78,176 KB
testcase_20 AC 344 ms
78,844 KB
testcase_21 AC 326 ms
79,176 KB
testcase_22 AC 330 ms
77,816 KB
testcase_23 AC 318 ms
78,356 KB
testcase_24 AC 333 ms
77,052 KB
testcase_25 AC 335 ms
76,516 KB
testcase_26 AC 339 ms
76,856 KB
testcase_27 AC 337 ms
77,264 KB
testcase_28 AC 353 ms
76,536 KB
testcase_29 AC 139 ms
76,608 KB
testcase_30 AC 99 ms
76,648 KB
testcase_31 AC 163 ms
77,604 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