結果

問題 No.1936 Rational Approximation
ユーザー lilictakalilictaka
提出日時 2022-09-06 00:47:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,544 KB
実行使用メモリ 53,548 KB
最終ジャッジ日時 2024-05-01 02:07:01
合計ジャッジ時間 1,835 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,332 KB
testcase_01 AC 41 ms
53,376 KB
testcase_02 AC 37 ms
53,184 KB
testcase_03 AC 37 ms
52,548 KB
testcase_04 AC 38 ms
53,548 KB
testcase_05 AC 38 ms
52,068 KB
testcase_06 AC 40 ms
52,632 KB
testcase_07 AC 37 ms
52,500 KB
testcase_08 AC 37 ms
53,348 KB
testcase_09 AC 38 ms
52,252 KB
testcase_10 AC 38 ms
52,816 KB
testcase_11 AC 37 ms
52,936 KB
testcase_12 AC 37 ms
52,696 KB
testcase_13 AC 38 ms
52,524 KB
testcase_14 AC 40 ms
52,808 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