結果

問題 No.2526 Kth Not-divisible Number
ユーザー noriocnorioc
提出日時 2023-11-04 18:52:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,118 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 76,456 KB
最終ジャッジ日時 2023-11-04 18:53:02
合計ジャッジ時間 10,599 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,736 KB
testcase_01 AC 37 ms
53,736 KB
testcase_02 AC 36 ms
53,736 KB
testcase_03 AC 1,084 ms
76,112 KB
testcase_04 AC 1,084 ms
76,076 KB
testcase_05 AC 1,085 ms
76,104 KB
testcase_06 AC 1,063 ms
76,100 KB
testcase_07 AC 1,118 ms
76,112 KB
testcase_08 AC 840 ms
76,100 KB
testcase_09 AC 796 ms
76,108 KB
testcase_10 AC 921 ms
76,112 KB
testcase_11 AC 392 ms
76,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import lcm


# n 以下の k の倍数の個数
def f(n, k):
    return n // k


# n 以下の数のうち、C でも D でも割り切れない数の個数
def g(n, a, b):
    assert a != b
    return n - f(n, a) - f(n, b) + f(n, lcm(a, b))


T = int(input())
for _ in range(T):
    A, B, K = map(int, input().split())
    lo = 1
    hi = K + (f(K, A) + f(K, B)) * 3
    res = hi
    while lo <= hi:
        m = (lo + hi) // 2
        cnt = g(m, A, B)
        if cnt >= K:
            res = min(res, m)
            hi = m - 1
        else:
            lo = m + 1

    print(res)
0