結果

問題 No.2526 Kth Not-divisible Number
ユーザー t98slider
提出日時 2023-11-03 21:25:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 541 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 192,396 KB
最終ジャッジ日時 2025-02-17 17:33:15
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        ll a, b, k;
        cin >> a >> b >> k;
        ll ng = 0, ok = (1ll << 61) - 1 + (1ll << 61), mid;
        auto f = [&](ll v){
            ll res = v;
            res -= v / a + v / b;
            res += v / lcm(a, b);
            return res;
        };
        while(ng + 1 < ok){
            mid = (ok + ng) / 2;
            (f(mid) >= k ? ok : ng) = mid;
        }
        cout << ok << '\n';
    }
}
0