結果

問題 No.2526 Kth Not-divisible Number
ユーザー otoshigootoshigo
提出日時 2023-11-03 21:38:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 201,696 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:38:21
合計ジャッジ時間 5,173 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 202 ms
4,348 KB
testcase_04 AC 202 ms
4,348 KB
testcase_05 AC 202 ms
4,348 KB
testcase_06 AC 204 ms
4,348 KB
testcase_07 AC 226 ms
4,348 KB
testcase_08 AC 184 ms
4,348 KB
testcase_09 AC 185 ms
4,348 KB
testcase_10 AC 187 ms
4,348 KB
testcase_11 AC 176 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

using ull=unsigned long long;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--){
        ull A,B,K;
        cin>>A>>B>>K;
        ull l=A*B/gcd(A,B);
        ull ng=0,ok=numeric_limits<ull>::max();
        while(ok-ng>1){
            ull mid=(ok+ng)/2;
            if(mid-mid/A-mid/B+mid/l>=K)ok=mid;
            else ng=mid;
        }
        cout<<ok<<"\n";
    }
}
0