結果

問題 No.1936 Rational Approximation
ユーザー 👑 KazunKazun
提出日時 2022-05-13 22:02:00
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 691 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 79,920 KB
最終ジャッジ日時 2023-09-29 07:14:20
合計ジャッジ時間 8,574 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,779 ms
79,920 KB
testcase_01 AC 1,200 ms
75,536 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 #

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

    flag=1
    while flag and (lu or ru):
        flag=0
        s=a+c; t=b+d

        if t*p<s*q:
            flag=1
            c,d=s,t
            if t<=n:
                rx,ry=s,t
            else:
                lu=0
        if t*p>s*q:
            flag=1
            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