結果

問題 No.2526 Kth Not-divisible Number
ユーザー keisuke6keisuke6
提出日時 2023-11-03 21:55:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 464 ms / 2,000 ms
コード長 440 bytes
コンパイル時間 3,076 ms
コンパイル使用メモリ 202,528 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:55:09
合計ジャッジ時間 7,731 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 438 ms
4,348 KB
testcase_04 AC 464 ms
4,348 KB
testcase_05 AC 437 ms
4,348 KB
testcase_06 AC 440 ms
4,348 KB
testcase_07 AC 462 ms
4,348 KB
testcase_08 AC 278 ms
4,348 KB
testcase_09 AC 257 ms
4,348 KB
testcase_10 AC 328 ms
4,348 KB
testcase_11 AC 239 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	int T;
	cin>>T;
	while(T--){
		int a,b,k;
		cin>>a>>b>>k;
		int t = lcm(a,b);
		int ad = (k/(t-t/a-t/b+1))*t;
		k %= (t-t/a-t/b+1);
		if(k == 0){
			cout<<ad-1<<endl;
			continue;
		}
		int l = 1, r = t;
		while(r-l > 1){
			int md = (l+r)/2;
			if(md-md/a-md/b <= k) l = md;
			else r = md;
		}
		while(l%a == 0 || l%b == 0) l--;
		cout<<ad+l<<endl;
	}
}
0