我们知道,在数学中,对于任意两个正整数a和b,必定存在一对整数s、t使得sa+tb=gcd(a,b)。
2 4 3 8 737 635
1 0 3 -1 193 -224
思路:扩展的欧几里得定理,百度搜了一下~
my code:
 
#include<iostream>
#include<stdio.h>
using namespace std;
int s,t;
void extend(int a,int b)
{
	if(b==0)
	{
       s=1;
	   t=0;
	}
	else
	{
		extend(b,a%b);
		int temp=s;
		s=t;
		t=temp-a/b*t;
	}
}
int main()
{
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		extend(a,b);
       cout<<s<<" "<<t<<endl;
	}
	return 0;
}        版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/zuguodexiaoguoabc/article/details/46761219