結果

問題 No.1936 Rational Approximation
ユーザー kotatsugamekotatsugame
提出日時 2021-10-30 01:25:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 370 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 65,208 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-20 06:36:25
合計ジャッジ時間 4,196 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
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 Lq=0,Lp=1,Rq=1,Rp=0;
	for(int a=1;a<P;a++)
	{
		{
			long b=(Q*a+P-1)/P-1;
			while(gcd(a,b)>1)b--;
			if(Lq*a<b*Lp)Lq=b,Lp=a;
		}
		{
			long b=Q*a/P+1;
			while(gcd(a,b)>1)b++;
			if(Rq*a>b*Rp)Rq=b,Rp=a;
		}
	}
	cout<<Lq+Lp+Rq+Rp<<endl;
}
0