結果

問題 No.2526 Kth Not-divisible Number
ユーザー wgrape
提出日時 2023-12-13 09:51:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,116 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-09-27 05:16:51
合計ジャッジ時間 10,847 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
import math
def is_ok(x,a,b,k): # xに対して、aでもbでも割り切れない数がk個以上存在すればTrue
    g = math.gcd(a, b)
    L = a // g * b
    cnt = x - (x // a) - (x // b) + (x // L)
    return cnt >= k

for _ in range(T):
    A,B,K = map(int,input().split())
    ok = 10 ** 19
    ng = 0
    while abs(ok - ng) > 1:
        mid = abs(ok + ng) // 2
        if is_ok(mid, A, B, K):
            ok = mid
        else:
            ng = mid
    print(ok)
0