結果

問題 No.2066 Simple Math !
ユーザー tamatotamato
提出日時 2022-09-02 22:28:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,224 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,768 KB
実行使用メモリ 78,596 KB
最終ジャッジ日時 2024-04-27 22:03:50
合計ジャッジ時間 17,909 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,724 KB
testcase_01 AC 76 ms
76,280 KB
testcase_02 AC 123 ms
76,424 KB
testcase_03 AC 64 ms
74,088 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 820 ms
76,988 KB
testcase_10 AC 809 ms
76,968 KB
testcase_11 AC 814 ms
76,812 KB
testcase_12 AC 814 ms
77,624 KB
testcase_13 AC 821 ms
76,700 KB
testcase_14 AC 782 ms
77,004 KB
testcase_15 AC 790 ms
76,700 KB
testcase_16 AC 791 ms
77,016 KB
testcase_17 AC 793 ms
77,020 KB
testcase_18 AC 777 ms
77,424 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 430 ms
76,996 KB
testcase_25 AC 428 ms
77,240 KB
testcase_26 AC 427 ms
77,212 KB
testcase_27 AC 431 ms
77,236 KB
testcase_28 AC 431 ms
76,828 KB
testcase_29 AC 243 ms
77,252 KB
testcase_30 AC 65 ms
73,284 KB
testcase_31 AC 109 ms
77,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    from math import gcd
    input = sys.stdin.readline

    # sum([(a * i + b) // m for i in range(n)])
    def floor_sum(n, m, a, b):
        ret = 0
        while True:
            ret += (a // m) * n * (n - 1) // 2 + (b // m) * n
            a %= m
            b %= m
            y = (a * n + b) // m
            x = b - y * m
            if y == 0:
                return ret
            ret += (x // a + n) * y
            n, m, a, b = y, a, m, x % a

    for _ in range(int(input())):
        p, q, k = map(int, input().split())
        g = gcd(p, q)
        p //= g
        q //= g
        if p > q:
            p, q = q, p

        k0 = floor_sum(q, q, p, p) + q - 1
        if k >= k0:
            ans = p * q + (k - k0)
            print(ans * g)
        else:
            ok = p * q
            ng = 0
            mid = (ok + ng) // 2
            while ok - ng > 1:
                x0 = mid // p
                tmp = floor_sum(x0+1, q, p, mid - p * x0) + x0
                if tmp >= k:
                    ok = mid
                else:
                    ng = mid
                mid = (ok + ng) // 2
            print(ok)


if __name__ == '__main__':
    main()
0