結果

問題 No.2066 Simple Math !
ユーザー kotatsugamekotatsugame
提出日時 2022-08-02 19:58:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 76,320 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-09 21:12:55
合計ジャッジ時間 8,004 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 64 ms
4,388 KB
testcase_02 AC 78 ms
4,380 KB
testcase_03 AC 53 ms
4,376 KB
testcase_04 AC 242 ms
4,380 KB
testcase_05 AC 240 ms
4,380 KB
testcase_06 AC 241 ms
4,376 KB
testcase_07 AC 241 ms
4,376 KB
testcase_08 AC 240 ms
4,380 KB
testcase_09 AC 240 ms
4,380 KB
testcase_10 AC 241 ms
4,376 KB
testcase_11 AC 238 ms
4,380 KB
testcase_12 AC 240 ms
4,380 KB
testcase_13 AC 240 ms
4,380 KB
testcase_14 AC 214 ms
4,376 KB
testcase_15 AC 215 ms
4,376 KB
testcase_16 AC 214 ms
4,380 KB
testcase_17 AC 215 ms
4,380 KB
testcase_18 AC 215 ms
4,380 KB
testcase_19 AC 152 ms
4,380 KB
testcase_20 AC 154 ms
4,380 KB
testcase_21 AC 152 ms
4,376 KB
testcase_22 AC 153 ms
4,380 KB
testcase_23 AC 153 ms
4,380 KB
testcase_24 AC 213 ms
4,380 KB
testcase_25 AC 211 ms
4,380 KB
testcase_26 AC 210 ms
4,380 KB
testcase_27 AC 209 ms
4,380 KB
testcase_28 AC 210 ms
4,380 KB
testcase_29 AC 61 ms
4,376 KB
testcase_30 AC 58 ms
4,376 KB
testcase_31 AC 80 ms
4,376 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);
}
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