結果

問題 No.2526 Kth Not-divisible Number
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-22 13:48:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 108,100 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 22:20:59
合計ジャッジ時間 7,460 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 505 ms
4,348 KB
testcase_04 AC 505 ms
4,348 KB
testcase_05 AC 496 ms
4,348 KB
testcase_06 AC 506 ms
4,348 KB
testcase_07 AC 500 ms
4,348 KB
testcase_08 AC 447 ms
4,348 KB
testcase_09 AC 446 ms
4,348 KB
testcase_10 AC 454 ms
4,348 KB
testcase_11 AC 410 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

ll A, B, C, K;

bool judge(ll X){
    return X-(X/A+X/B-X/C) >= K;
}

void solve(){

    cin >> A >> B >> K;
    assert(A != B);
    assert(2 <= A && A <= 1e9);
    assert(2 <= B && B <= 1e9);
    assert(1 <= K && K <= 1e18);
    C = A*B/gcd(A,B);

    ll l=0, r=4e18, c;
    while(r-l>1){
        c = (l+r)/2;
        if (judge(c)) r=c;
        else l=c;
    }
  
    cout << r << endl;
    return;
}

int main(){

    ll T;
    cin >> T;

    while(T){
        T--;
        solve();
    }

    return 0;
}
0