結果

問題 No.2526 Kth Not-divisible Number
ユーザー srjywrdnprkt
提出日時 2024-02-09 19:49:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 399 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 193,236 KB
最終ジャッジ日時 2025-02-19 03:06:46
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve(){
    ll a, b, c, l;
    cin >> a >> b >> c;
    l = lcm(a, b);
    auto f=[&](ll z){
        return z-z/a-z/b+z/l >= c;
    };
    ll ng = 0, ok = 9e18, mid;
    while(ok-ng>1){
        mid = (ok+ng)/2;
        if (f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int t;
    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
0