結果

問題 No.1936 Rational Approximation
ユーザー Akijin_007Akijin_007
提出日時 2022-05-13 22:55:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 503 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,336 KB
実行使用メモリ 71,240 KB
最終ジャッジ日時 2023-09-29 08:34:27
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,144 KB
testcase_01 AC 69 ms
70,936 KB
testcase_02 AC 69 ms
71,048 KB
testcase_03 AC 71 ms
70,732 KB
testcase_04 AC 74 ms
71,192 KB
testcase_05 AC 70 ms
71,184 KB
testcase_06 AC 69 ms
71,192 KB
testcase_07 AC 70 ms
71,232 KB
testcase_08 AC 70 ms
70,732 KB
testcase_09 AC 70 ms
71,068 KB
testcase_10 AC 70 ms
71,072 KB
testcase_11 AC 69 ms
71,196 KB
testcase_12 AC 70 ms
70,736 KB
testcase_13 AC 70 ms
71,240 KB
testcase_14 AC 71 ms
70,928 KB
権限があれば一括ダウンロードができます

ソースコード

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