結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 117 ms
75,312 KB
testcase_04 AC 115 ms
74,908 KB
testcase_05 AC 115 ms
74,960 KB
testcase_06 AC 114 ms
74,848 KB
testcase_07 AC 116 ms
74,744 KB
testcase_08 AC 117 ms
74,972 KB
testcase_09 AC 117 ms
74,908 KB
testcase_10 AC 115 ms
74,928 KB
testcase_11 AC 114 ms
75,248 KB
testcase_12 AC 114 ms
74,848 KB
testcase_13 AC 115 ms
75,316 KB
testcase_14 AC 115 ms
75,036 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<=10**7 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