結果

問題 No.2526 Kth Not-divisible Number
ユーザー cho435cho435
提出日時 2023-11-03 22:08:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 604 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 4,307 ms
コンパイル使用メモリ 262,408 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-11-03 22:08:36
合計ジャッジ時間 10,845 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 602 ms
4,348 KB
testcase_04 AC 577 ms
4,348 KB
testcase_05 AC 602 ms
4,348 KB
testcase_06 AC 578 ms
4,372 KB
testcase_07 AC 604 ms
4,372 KB
testcase_08 AC 513 ms
4,372 KB
testcase_09 AC 480 ms
4,372 KB
testcase_10 AC 519 ms
4,372 KB
testcase_11 AC 417 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

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

int main(){
	int t;
	cin>>t;
	rep(Ti,t){
		ll a,b,k;
		cin>>a>>b>>k;
		ll l=a/gcd(a,b)*b;
		ll up=9e18;
		ll dw=0;
		while(up-dw>1){
			ll md=((__int128_t)up+dw)/2;
			ll ct=0;
			ct+=md/a;
			ct+=md/b;
			ct-=md/l;
			if(md-ct>=k) up=md;
			else dw=md;
		}
		cout<<up<<"\n";
	}
}
0