Euclid'in Genişletilmiş Algoritması ile ilgili bir sorun yaşıyorum. (ax + by = gcd (a, b)) Hem GCD'yi hem de x ve y'yi belirlemeye çalışıyorum. GCD bir sorun değil, döngü yöntemini kullanarak x ve y ile bir şeyler ters gidiyor. Normalde bir sayı 0, diğeri anormal derecede büyük bir negatif sayıdır. Kod aşağıdaki gibidir: atamalarıeuclid'in genişletilmiş algoritması C++
#include <iostream>
using namespace std;
main()
{
int a,b,q,x,lastx,y,lasty,temp,temp1,temp2,temp3;
cout << "Please input a" << endl;
cin >> a;
cout << "Please input b" << endl;
cin >> b;
if (b>a) {//we switch them
temp=a; a=b; b=temp;
}
//begin function
x=0;
y=1;
lastx=1;
lasty=0;
while (b!=0) {
q= a/b;
temp1= a%b;
a=b;
b=temp1;
temp2=x-q*x;
x=lastx-q*x;
lastx=temp2;
temp3=y-q*y;
y=lasty-q*y;
lasty=temp3;
}
cout << "gcd" << a << endl;
cout << "x=" << lastx << endl;
cout << "y=" << lasty << endl;
return 0;
}
Çok teşekkür ederim =! – user1735851