結果

問題 No.2526 Kth Not-divisible Number
ユーザー srjywrdnprkt
提出日時 2023-06-22 13:48:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 524 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 104,160 KB
最終ジャッジ日時 2025-02-15 00:08:01
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

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