现在的位置: 首页 > 综合 > 正文

templete_extgcd

2013年06月23日 ⁄ 综合 ⁄ 共 330字 ⁄ 字号 评论关闭
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>

using namespace std;

typedef long long LL;

int extgcd(int a, int b, LL &d, LL &x, LL &y)
{
	if (b == 0)
	{
		d = a;
		x = 1;
		y = 0;
	}
	else
	{
		extgcd(b, a % b, d, y, x);
		y -= x * (a / b);
	}
}

int main()
{
	LL x, y, d;
	extgcd(15, 6, d, x, y);
	cout << "gcd(a, b) = " << d << endl;
	cout << "x = " << x << endl;
	cout << "y = " << y << endl;
	system("pause");
	return 0;
}

抱歉!评论已关闭.