結果

問題 No.1936 Rational Approximation
ユーザー lilictakalilictaka
提出日時 2022-09-06 00:47:44
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 71,588 KB
最終ジャッジ日時 2023-08-13 08:27:44
合計ジャッジ時間 2,452 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,240 KB
testcase_01 AC 73 ms
71,320 KB
testcase_02 AC 72 ms
71,516 KB
testcase_03 AC 73 ms
71,304 KB
testcase_04 AC 75 ms
71,172 KB
testcase_05 AC 72 ms
71,484 KB
testcase_06 AC 72 ms
71,364 KB
testcase_07 AC 72 ms
71,420 KB
testcase_08 AC 71 ms
71,268 KB
testcase_09 AC 72 ms
71,500 KB
testcase_10 AC 74 ms
71,472 KB
testcase_11 AC 72 ms
71,516 KB
testcase_12 AC 74 ms
71,588 KB
testcase_13 AC 73 ms
71,308 KB
testcase_14 AC 73 ms
71,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extGCD(a,b):#ax + by = gcd(a,b)->return (x,y)
    x, y, u, v = 1, 0, 0, 1
    while b:
        k = a // b
        x -= k * u
        y -= k * v
        x, u = u, x
        y, v = v, y
        a, b = b, a % b
    return x, y
P,Q = map(int,input().split())
x,y = extGCD(P,Q)
m = (-x//Q) + 1
ql = x + Q * m
pl = -(y-P*m)
x,y = extGCD(Q,P)
m = (-x//P) + 1
pr = x + P * m
qr = -(y-Q * m)
print(pl+ql+ pr+qr)
0