結果

問題 No.2526 Kth Not-divisible Number
ユーザー noriocnorioc
提出日時 2023-11-04 00:01:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,141 ms / 2,000 ms
コード長 585 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 81,752 KB
実行使用メモリ 76,032 KB
最終ジャッジ日時 2023-11-04 00:01:22
合計ジャッジ時間 11,064 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,676 KB
testcase_01 AC 36 ms
53,676 KB
testcase_02 AC 35 ms
53,676 KB
testcase_03 AC 1,141 ms
76,024 KB
testcase_04 AC 1,103 ms
76,028 KB
testcase_05 AC 1,100 ms
76,032 KB
testcase_06 AC 1,113 ms
76,032 KB
testcase_07 AC 1,116 ms
76,032 KB
testcase_08 AC 802 ms
76,032 KB
testcase_09 AC 762 ms
76,028 KB
testcase_10 AC 901 ms
76,028 KB
testcase_11 AC 733 ms
76,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd, 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))


INF = 1 << 62
T = int(input())
for _ in range(T):
    A, B, K = map(int, input().split())
    lo = 1
    hi = INF
    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