結果

問題 No.2526 Kth Not-divisible Number
ユーザー daiotadaiota
提出日時 2023-11-04 20:40:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 430 ms / 2,000 ms
コード長 669 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 166,960 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-11-04 20:40:54
合計ジャッジ時間 7,438 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 407 ms
4,372 KB
testcase_04 AC 406 ms
4,372 KB
testcase_05 AC 430 ms
4,372 KB
testcase_06 AC 406 ms
4,372 KB
testcase_07 AC 413 ms
4,372 KB
testcase_08 AC 376 ms
4,372 KB
testcase_09 AC 374 ms
4,372 KB
testcase_10 AC 387 ms
4,372 KB
testcase_11 AC 368 ms
4,372 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;

      }


     cout << ok << endl;

}

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