galois.egcd

galois.egcd(a, b)

Finds the integer multiplicands of \(a\) and \(b\) such that \(a x + b y = \mathrm{gcd}(a, b)\).

This function implements the Extended Euclidean Algorithm.

Parameters
  • a (int) – Any integer.

  • b (int) – Any integer.

Returns

  • int – Greatest common divisor of \(a\) and \(b\).

  • int – Integer \(x\), such that \(a x + b y = \mathrm{gcd}(a, b)\).

  • int – Integer \(y\), such that \(a x + b y = \mathrm{gcd}(a, b)\).

References

Examples

In [1]: a = 12

In [2]: b = 28

In [3]: gcd, x, y = galois.egcd(a, b)

In [4]: gcd, x, y
Out[4]: (4, -2, 1)

In [5]: a*x + b*y == gcd
Out[5]: True