結果

問題 No.2066 Simple Math !
ユーザー 👑 rin204rin204
提出日時 2022-09-02 23:29:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 822 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,112 KB
実行使用メモリ 78,668 KB
最終ジャッジ日時 2024-04-27 23:10:01
合計ジャッジ時間 21,202 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,072 KB
testcase_01 AC 297 ms
76,828 KB
testcase_02 AC 346 ms
76,744 KB
testcase_03 AC 160 ms
76,756 KB
testcase_04 AC 794 ms
77,380 KB
testcase_05 AC 803 ms
77,568 KB
testcase_06 AC 805 ms
77,752 KB
testcase_07 AC 797 ms
77,320 KB
testcase_08 AC 801 ms
77,584 KB
testcase_09 AC 822 ms
77,624 KB
testcase_10 AC 813 ms
77,508 KB
testcase_11 AC 796 ms
77,416 KB
testcase_12 AC 807 ms
77,396 KB
testcase_13 AC 808 ms
77,520 KB
testcase_14 AC 710 ms
77,796 KB
testcase_15 AC 709 ms
77,764 KB
testcase_16 AC 715 ms
77,956 KB
testcase_17 AC 710 ms
77,524 KB
testcase_18 AC 711 ms
77,992 KB
testcase_19 AC 562 ms
78,428 KB
testcase_20 AC 561 ms
78,208 KB
testcase_21 AC 557 ms
78,400 KB
testcase_22 AC 557 ms
78,668 KB
testcase_23 AC 563 ms
78,192 KB
testcase_24 AC 705 ms
77,560 KB
testcase_25 AC 700 ms
77,268 KB
testcase_26 AC 698 ms
77,440 KB
testcase_27 AC 697 ms
77,448 KB
testcase_28 AC 698 ms
77,684 KB
testcase_29 AC 263 ms
77,280 KB
testcase_30 AC 166 ms
76,480 KB
testcase_31 AC 244 ms
77,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

# return (\sum_{i=0}^{n-1} ((a*i+b)//m))
def floor_sum(n, m, a, b):
    ret = 0
    while True:
        if a >= m:
            ret += ((n - 1) * n) // 2 * (a // m)
            a %= m
        if b >= m:
            ret += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        if y_max == 0:
            return ret
        x_max = y_max * m - b
        ret += (n - (x_max + a - 1) // a) * y_max
        n, m, a, b = y_max, a, m, -x_max % a




def solve(p, q, k):
    l = 0
    r = 1 << 60

    def cnt(x):
        n = min(q, x // p + 1)
        return floor_sum(n, q, p, q + x - p * (n - 1))

    while r - l > 1:
        mid = (l + r) // 2        
        if cnt(mid) > k:
            r = mid
        else:
            l = mid
    return r


for _ in range(int(input())):
    p, q, k = map(int, input().split())
    g = gcd(p, q)
    p //= g
    q //= g
    print(g * solve(p, q, k))
0