結果

問題 No.2526 Kth Not-divisible Number
ユーザー GOTKAKOGOTKAKO
提出日時 2023-11-03 21:43:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 202,380 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:43:57
合計ジャッジ時間 6,127 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 328 ms
4,348 KB
testcase_04 AC 327 ms
4,348 KB
testcase_05 AC 333 ms
4,348 KB
testcase_06 AC 328 ms
4,348 KB
testcase_07 AC 329 ms
4,348 KB
testcase_08 AC 200 ms
4,348 KB
testcase_09 AC 179 ms
4,348 KB
testcase_10 AC 216 ms
4,348 KB
testcase_11 AC 191 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

    int test; cin >> test;
    while(test--){
        long long A,B,K; cin >> A >> B >> K;
        if(A > B) swap(A,B);
        long long G = gcd(A,B),L = A*B/G;
        long long loop = L-(L/A+L/B-1);
        long long answer = max(0LL,L*(K/loop));
        K %= loop;
        if(K == 0) answer--;
        
        long long low = -1,high = L-1;
        while(high-low > 1){
            long long mid = (high+low)/2;
            long long now = mid-(mid/A+mid/B);
            if(now >= K) high = mid;
            else low = mid;
        }
        cout << answer+high << endl;
    }
}
0