結果
問題 |
No.1936 Rational Approximation
|
ユーザー |
👑 ![]() |
提出日時 | 2022-05-13 22:05:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 665 bytes |
コンパイル時間 | 340 ms |
コンパイル使用メモリ | 81,912 KB |
実行使用メモリ | 54,412 KB |
最終ジャッジ日時 | 2024-07-22 01:58:05 |
合計ジャッジ時間 | 1,553 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 WA * 3 |
ソースコード
#参考元 #https://tjkendev.github.io/procon-library/python/math/stern-brocot-tree.html def Stern_Brocot(p,q,n): a,b,c,d=0,1,1,0 lu,ru=1,1 lx,ly,rx,ry=0,1,1,0 times=0 while times<=1000 and (lu or ru): times+=1 s=a+c; t=b+d if t*p<s*q: c,d=s,t if t<=n: rx,ry=s,t else: lu=0 if t*p>s*q: a,b=s,t if t<=n: lx,ly=s,t else: ru=0 return lx,ly,rx,ry #================================================== P,Q=map(int,input().split()) a,b,c,d=Stern_Brocot(P,Q,Q) print(a+b+c+d)