結果

問題 No.1936 Rational Approximation
ユーザー kotatsugamekotatsugame
提出日時 2021-10-30 01:13:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 370 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 63,204 KB
実行使用メモリ 11,476 KB
最終ジャッジ日時 2023-09-20 06:36:39
合計ジャッジ時間 4,077 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
long P,Q;
int main()
{
	cin>>P>>Q;
	long Lp=0,Lq=1,Rp=1,Rq=0;
	for(int a=1;a<P;a++)
	{
		{
			long b=P*a/Q+1;
			while(gcd(a,b)>1)b++;
			if(Lp*b<a*Lq)Lp=a,Lq=b;
		}
		{
			long b=(P*a+Q-1)/Q-1;
			while(gcd(a,b)>1)b--;
			if(Rp*b>a*Rq)Rp=a,Rq=b;
		}
	}
	cout<<Lp+Lq+Rp+Rq<<endl;
}
0