結果

問題 No.2526 Kth Not-divisible Number
ユーザー daiota
提出日時 2023-11-04 20:41:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 669 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 167,364 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 22:19:17
合計ジャッジ時間 6,137 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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=2e18;

     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