結果

問題 No.1936 Rational Approximation
ユーザー 👑 Kazun
提出日時 2022-05-13 22:05:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 666 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 57,984 KB
最終ジャッジ日時 2024-07-22 01:58:31
合計ジャッジ時間 2,421 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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