求解一组ax+bc=gcd(a,b)
#include<iostream> #include<cstdio> using namespace std; int exgcd(int A,int B,int &x,int &y){ if(B==0){ x=1;y=0;return A; } int ret=exgcd(B,A%B,x,y); int t=x;x=y;y=t-A/B*y; return ret; } int main(){ int a,b,x,y; while(cin>>a>>b){ int g=exgcd(a,b,x,y); cout<<a<<"*"<<x<<"+"<<b<<"*"<<y<<"="<<g<<endl; } }