結果

問題 No.2526 Kth Not-divisible Number
ユーザー noriocnorioc
提出日時 2023-11-03 22:57:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,096 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 76,104 KB
最終ジャッジ日時 2023-11-03 22:57:58
合計ジャッジ時間 11,010 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,696 KB
testcase_01 AC 38 ms
53,696 KB
testcase_02 AC 36 ms
53,696 KB
testcase_03 AC 1,096 ms
76,088 KB
testcase_04 AC 1,078 ms
76,096 KB
testcase_05 AC 1,075 ms
76,096 KB
testcase_06 AC 1,059 ms
76,104 KB
testcase_07 AC 1,093 ms
76,104 KB
testcase_08 AC 833 ms
76,096 KB
testcase_09 AC 784 ms
76,104 KB
testcase_10 AC 865 ms
76,104 KB
testcase_11 AC 730 ms
76,096 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)
        # print(f'{m=} {cnt=}')
        if cnt == K:
            res = min(res, m)
            hi = m - 1
        elif cnt < K:
            lo = m + 1
        else:
            hi = m - 1

    print(res)
0