結果

問題 No.1936 Rational Approximation
ユーザー 👑 KazunKazun
提出日時 2022-05-13 22:05:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 665 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 71,548 KB
最終ジャッジ日時 2023-09-29 07:22:16
合計ジャッジ時間 2,230 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 71 ms
70,996 KB
testcase_04 AC 73 ms
71,000 KB
testcase_05 AC 70 ms
70,836 KB
testcase_06 AC 72 ms
70,956 KB
testcase_07 AC 71 ms
70,828 KB
testcase_08 AC 70 ms
70,904 KB
testcase_09 AC 70 ms
71,052 KB
testcase_10 AC 71 ms
71,004 KB
testcase_11 AC 73 ms
70,980 KB
testcase_12 AC 71 ms
70,696 KB
testcase_13 AC 70 ms
71,108 KB
testcase_14 AC 72 ms
70,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#参考元
#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)
0