扩展欧几里德算法(待补充)
已知 ab 求 一组解 x,y 满足 ax+by = gcd(a, b) 这个公式
#include<cstdio>
typedef long long LL;
void extend_Eulid(LL a, LL b, LL &x, LL &y, LL &d){
if (!b) {d = a, x = 1, y = 0;}
else{
extend_Eulid(b, a % b, y, x, d);
y -= x * (a / b);
}
}
int main(){
LL a, b, d, x, y;
while(~scanf("%lld%lld", &a, &b)){
extend_Eulid(a, b, x, y, d);
printf("%lld*a + %lld*b = %lld\n", x, y, d);
}
}