結果

問題 No.2526 Kth Not-divisible Number
ユーザー daiotadaiota
提出日時 2023-11-04 20:37:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 170,736 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-04 20:37:28
合計ジャッジ時間 7,294 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 424 ms
4,348 KB
testcase_04 AC 422 ms
4,348 KB
testcase_05 AC 447 ms
4,348 KB
testcase_06 AC 421 ms
4,348 KB
testcase_07 AC 420 ms
4,348 KB
testcase_08 AC 393 ms
4,348 KB
testcase_09 AC 387 ms
4,348 KB
testcase_10 AC 394 ms
4,348 KB
testcase_11 AC 382 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)



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


ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

ll L;
void find(ll a,ll b,ll k){
     ll ng=0,ok=4e18;

     while(ok-ng>1){

          ll mid=(ng+ok)/2;

          if(k+mid/a+mid/b-mid/L<=mid) ok=mid;
          else ng=mid;

      }

     vector<ll> v;
     v.push_back(ok);
     if(ok>1) v.push_back(ok-1);
     if(ok>2) v.push_back(ok-2);
     if(ok>3) v.push_back(ok-3);

     for(int i=0;i<(int)v.size();i++) if(v[i]%a!=0 && v[i]%b!=0){
    	 cout << v[i] << endl;
    	 break;
     }

}

int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	int i,j;

	int T;
	cin >> T;
	while(T--){

		ll A,B,K;
		cin >> A >> B >> K;

		L=lcm(A,B);

		find(A,B,K);

	}



	return 0;
}
0