結果

問題 No.2526 Kth Not-divisible Number
ユーザー kotatsugamekotatsugame
提出日時 2023-11-03 21:23:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 436 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 64,596 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:30:26
合計ジャッジ時間 4,489 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 273 ms
4,348 KB
testcase_04 AC 273 ms
4,348 KB
testcase_05 AC 274 ms
4,348 KB
testcase_06 AC 273 ms
4,348 KB
testcase_07 AC 273 ms
4,348 KB
testcase_08 AC 248 ms
4,348 KB
testcase_09 AC 245 ms
4,348 KB
testcase_10 AC 252 ms
4,348 KB
testcase_11 AC 236 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
using namespace std;
int gcd(int a,int b)
{
	while(b)
	{
		int t=a%b;
		a=b;
		b=t;
	}
	return a;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		int A,B;
		long K;
		cin>>A>>B>>K;
		int g=gcd(A,B);
		long lcm=(long)A/g*B;
		long L=0,R=4e18;
		while(R-L>1)
		{
			long M=(L+R)/2;
			if(M-(M/A+M/B-M/lcm)>=K)R=M;
			else L=M;
		}
		cout<<R<<"\n";
	}
}
0