結果

問題 No.2526 Kth Not-divisible Number
ユーザー inkyaman
提出日時 2024-03-24 16:06:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 741 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 1,084 ms
コンパイル使用メモリ 115,976 KB
最終ジャッジ日時 2025-02-20 13:39:59
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
#include <tuple>
using namespace std;
using ll = long long;

int T;

int main() {

    cin >> T;
    vector<ll> ans;
    while(T--) {
        ll A, B, K;
        cin >> A >> B >> K;
        ll l = 0, r = 3e18;
        while(r-l > 1) {
            ll mid = l+(r-l)/2;
            ll t = mid;
            t -= mid/A;
            t -= mid/B;
            t += mid/(A/gcd(A,B)*B);
            if(t >= K) r = mid;
            else l = mid;
        }

        ans.push_back(r);
        
    }

    for(auto v : ans) cout << v << endl;

}
0