расширенный евклидов алгоритм

эй, почему базовый случай расширенного евклидова алгоритма x = 1;
у = 0?

#include <iostream>

int d, x, y;
void extendedEuclid(int A, int B) {
if(B == 0) {
d = A;
x = 1;
y = 0;
}
else {
extendedEuclid(B, A%B);
int temp = x;
x = y;
y = temp - (A/B)*y;
}
}

int main( ) {
extendedEuclid(16, 10);
cout << "The GCD of 16 and 10 is " << d << endl;
cout << "Coefficients x and y are "<< x <<  "and  " << y << endl;
return 0;
}

Выход

The GCD of 16 and 10 is 2.
Coefficients x and y are 2 and -3.

Пожалуйста, помогите мне

-4

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector