扩展欧几里得

扩展欧几里得

1.

void exgcd (long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1; y = 0;
        return;
    }
    exgcd (b, a % b, y, x);
    y -= a / b * x;
}

2.

void exgcd (LL a, LL b, LL &x, LL &y) {
	if (b == 0) {
		x = 1; y = 0;
		return;
	}
	exgcd (b, a % b, x, y);
	LL t = x;
	x = y;
	y = t - (a / b) * y;
}
posted @ 2020-11-02 13:53  C2022lihan  阅读(23)  评论(0编辑  收藏  举报