結果

問題 No.2066 Simple Math !
ユーザー kotatsugamekotatsugame
提出日時 2022-08-02 19:31:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 76,616 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 15:40:09
合計ジャッジ時間 7,188 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 60 ms
6,940 KB
testcase_02 AC 75 ms
6,944 KB
testcase_03 AC 45 ms
6,944 KB
testcase_04 AC 206 ms
6,944 KB
testcase_05 AC 213 ms
6,940 KB
testcase_06 AC 212 ms
6,940 KB
testcase_07 AC 243 ms
6,940 KB
testcase_08 AC 209 ms
6,944 KB
testcase_09 AC 208 ms
6,944 KB
testcase_10 AC 206 ms
6,944 KB
testcase_11 AC 206 ms
6,944 KB
testcase_12 AC 201 ms
6,944 KB
testcase_13 AC 216 ms
6,940 KB
testcase_14 AC 190 ms
6,940 KB
testcase_15 AC 191 ms
6,940 KB
testcase_16 AC 191 ms
6,944 KB
testcase_17 AC 183 ms
6,940 KB
testcase_18 AC 193 ms
6,940 KB
testcase_19 AC 128 ms
6,940 KB
testcase_20 AC 137 ms
6,944 KB
testcase_21 AC 129 ms
6,944 KB
testcase_22 AC 130 ms
6,940 KB
testcase_23 AC 129 ms
6,940 KB
testcase_24 AC 191 ms
6,944 KB
testcase_25 AC 184 ms
6,948 KB
testcase_26 AC 183 ms
6,944 KB
testcase_27 AC 184 ms
6,940 KB
testcase_28 AC 178 ms
6,940 KB
testcase_29 AC 60 ms
6,944 KB
testcase_30 AC 48 ms
6,944 KB
testcase_31 AC 53 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<utility>
#include<atcoder/math>
using namespace std;
int gcd(int a,int b)
{
	while(b)
	{
		int t=a%b;
		a=b;
		b=t;
	}
	return a;
}
long long count(long long X,int P,int Q)
//Sum[floor((X-Pi+Q)/Q),{i,0,Q-1}]
{
	long long R=min((long long)Q,X/P+1);
	return atcoder::floor_sum(R,Q,P,X+Q-P*(R-1));
}
int main()
{
	int T;
	cin>>T;
	for(;T--;)
	{
		int P,Q,K;
		cin>>P>>Q>>K;
		int g=gcd(P,Q);
		P/=g;
		Q/=g;
		long long l=0,r=1e18;
		while(r-l>1)
		{
			long long mid=(l+r)/2;
			if(count(mid,P,Q)<=K)l=mid;
			else r=mid;
		}
		cout<<r*g<<endl;
	}
}
0