模板-gcd

GCD

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a%b);
}

EXGCD

void ex_gcd(int a, int b, int &x, int &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return;
	}
	else
	{
		ex_gcd(b, a%b, x, y);
		int t = x;
		x = y;
		y = t - (a / b)*y;
	}
}
posted @ 2018-09-08 15:40  Titordong  阅读(165)  评论(0编辑  收藏  举报