結果

問題 No.2526 Kth Not-divisible Number
ユーザー t98slidert98slider
提出日時 2023-11-03 21:25:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 604 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 202,088 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:25:30
合計ジャッジ時間 7,949 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 604 ms
4,348 KB
testcase_04 AC 597 ms
4,348 KB
testcase_05 AC 596 ms
4,348 KB
testcase_06 AC 595 ms
4,348 KB
testcase_07 AC 596 ms
4,348 KB
testcase_08 AC 390 ms
4,348 KB
testcase_09 AC 332 ms
4,348 KB
testcase_10 AC 441 ms
4,348 KB
testcase_11 AC 331 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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