結果

問題 No.1936 Rational Approximation
ユーザー kotatsugamekotatsugame
提出日時 2021-11-01 07:02:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 381 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 64,768 KB
実行使用メモリ 14,972 KB
最終ジャッジ日時 2023-09-20 06:36:32
合計ジャッジ時間 6,902 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
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 q=1;q<Q;q++)
	{
		{//L
			long p=(q*P+Q-1)/Q-1;
			while(p>0&&gcd(p,q)>1)p--;
			if(Lp*q<p*Lq)Lp=p,Lq=q;
		}
		{//R
			long p=P*q/Q+1;
			while(gcd(p,q)>1)p++;
			if(Rp*q>p*Rq)Rp=p,Rq=q;
		}
	}
	cout<<Lp+Lq+Rp+Rq<<endl;
}
0