結果

問題 No.2526 Kth Not-divisible Number
ユーザー GOTKAKOGOTKAKO
提出日時 2023-11-03 21:39:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 657 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 202,260 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:39:50
合計ジャッジ時間 5,845 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 = L*(K/loop);
        K %= loop;

        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