#include<stdio.h> int extended_gcd(int a,int b,int &x,int &y) { int r,t; if(!b) { x = 1; y = 0; return a; } r = extended_gcd(b,a%b,x,y); t = x; x = y; y = t-a/b*y; return r; } int main() { int a,b,x,y,z; scanf("%d%d",&a,&b); z = extended_gcd(a,b,x,y); printf("%d%d%d\n",z,x,y); return 0; }
扩展欧几里德算法—求解不定方程,线性同余方程,布布扣,bubuko.com
原文:http://www.cnblogs.com/yangyongqian/p/3894055.html