結果

問題 No.1936 Rational Approximation
ユーザー Akijin_007Akijin_007
提出日時 2022-05-13 22:54:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 500 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 71,692 KB
最終ジャッジ日時 2023-09-29 08:33:21
合計ジャッジ時間 2,316 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

P, Q = map(int, input().split())

def xgcd(a,b):
    prevx, nextx = 1, 0
    prevy, nexty = 0, 1
    while b:
        quotient = a//b
        nextx, prevx = prevx - quotient * nextx, nextx
        nexty, prevy = prevy - quotient * nexty, nexty
        a, b = b, a % b
        # print(a,b)
    return prevx, prevy,a

x, y, g = xgcd(P, -Q)

a, b = divmod(x, Q)
x -= Q * a
y -= P * a

mx = Q - x
my = P - y

print(x, y, mx, my)
0