結果

問題 No.2526 Kth Not-divisible Number
ユーザー momoyuumomoyuu
提出日時 2023-11-04 22:10:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 5,034 ms
コンパイル使用メモリ 242,992 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-04 22:10:24
合計ジャッジ時間 8,640 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 403 ms
4,348 KB
testcase_04 AC 412 ms
4,348 KB
testcase_05 AC 403 ms
4,348 KB
testcase_06 AC 409 ms
4,348 KB
testcase_07 AC 403 ms
4,348 KB
testcase_08 AC 373 ms
4,348 KB
testcase_09 AC 375 ms
4,348 KB
testcase_10 AC 378 ms
4,348 KB
testcase_11 AC 361 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


ll gcd(ll a,ll b){
    if(b) return gcd(b,a%b);
    return a;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int t;
    cin>>t;
    while(t--){
        ll a,b,k;
        cin>>a>>b>>k;
        ll right = 8e18;
        ll left = 0;
        ll g = gcd(a,b);
        g = a / g * b;
        while(right-left>1){
            ll mid = ((right-left)>>1) + left;
            ll cnt = mid / a + mid / b - mid / g;
            if(mid-cnt>=k) right = mid;
            else left = mid;
        }
        cout<<right<<endl;
    }

}
0