結果

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

ソースコード

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 = K * 2
    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