結果
| 問題 |
No.1936 Rational Approximation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-30 01:25:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 370 bytes |
| コンパイル時間 | 502 ms |
| コンパイル使用メモリ | 64,596 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-06 02:36:00 |
| 合計ジャッジ時間 | 3,815 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | AC * 2 TLE * 1 -- * 11 |
ソースコード
#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;
}