結果

問題 No.2066 Simple Math !
ユーザー tassei903tassei903
提出日時 2022-09-02 23:21:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 790 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 79,832 KB
最終ジャッジ日時 2024-04-27 23:02:43
合計ジャッジ時間 17,372 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,288 KB
testcase_01 AC 67 ms
76,272 KB
testcase_02 AC 98 ms
76,880 KB
testcase_03 AC 68 ms
76,148 KB
testcase_04 AC 672 ms
78,028 KB
testcase_05 AC 676 ms
78,612 KB
testcase_06 AC 757 ms
79,168 KB
testcase_07 AC 689 ms
78,208 KB
testcase_08 AC 693 ms
78,260 KB
testcase_09 AC 790 ms
79,424 KB
testcase_10 AC 670 ms
77,964 KB
testcase_11 AC 666 ms
77,844 KB
testcase_12 AC 690 ms
78,668 KB
testcase_13 AC 659 ms
78,020 KB
testcase_14 AC 614 ms
78,160 KB
testcase_15 AC 593 ms
77,876 KB
testcase_16 AC 636 ms
78,508 KB
testcase_17 AC 600 ms
78,108 KB
testcase_18 AC 629 ms
78,664 KB
testcase_19 AC 540 ms
79,832 KB
testcase_20 AC 421 ms
77,904 KB
testcase_21 AC 479 ms
78,700 KB
testcase_22 AC 511 ms
78,836 KB
testcase_23 AC 428 ms
78,132 KB
testcase_24 AC 662 ms
79,092 KB
testcase_25 AC 613 ms
78,208 KB
testcase_26 AC 598 ms
77,976 KB
testcase_27 AC 660 ms
79,036 KB
testcase_28 AC 575 ms
78,040 KB
testcase_29 AC 89 ms
76,360 KB
testcase_30 AC 67 ms
76,120 KB
testcase_31 AC 72 ms
76,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
def floor_sum(n, m, a, b):
    ans = 0
    # 領域①
    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
 
    # 領域④
    ans += floor_sum(y_max, a, m, (-x_max) % a)
    # ACLでは負数の剰余に注意して以下のように書かれている
    # ans += floor_sum(y_max, a, m, (a - x_max % a) % a) 
 
    return ans

def f(n):
    if n <= g * (P-1) * (Q-1):
        F = n//p + 1
        return floor_sum(F,q, p,n - (F-1) * p) + F
    else:
        return f(g * (P-1)*(Q-1)) + (n//g-(P-1)*(Q-1))


t = ni()
from math import gcd
for _ in range(t):
    p, q, k = na()
    k += 1
    g = gcd(p, q)
    P, Q = p//g, q//g
    ng = -1
    ok = 10**18
    while ok-ng > 1:
        d = (ok+ng)//2
        if f(d) >= k:
            ok = d
        else:
            ng = d
    print(ok)
0