結果

問題 No.2526 Kth Not-divisible Number
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-02 17:46:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 516 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 108,104 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:24:50
合計ジャッジ時間 6,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 496 ms
4,348 KB
testcase_05 AC 516 ms
4,348 KB
testcase_06 AC 514 ms
4,348 KB
testcase_07 AC 510 ms
4,348 KB
testcase_08 AC 455 ms
4,348 KB
testcase_09 AC 448 ms
4,348 KB
testcase_10 AC 464 ms
4,348 KB
testcase_11 AC 412 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;
    C = A*B/gcd(A,B);

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

    ll mi=max(1LL, l-5);
    for (ll X=mi; X<=l; X++){
        if (X-(X/A+X/B-X/C) == K && X % A != 0 && X % B != 0){
            cout << X << endl;
            return;
        }
    }

    return;
}

int main(){

    ll T;
    cin >> T;

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

    return 0;
}
0