The greatest common divisor, or gcd, of two numbers $a$ and $b$ is the only number $d$ such that
$d|a$ and $d|b$, and
$c|a$ and $c|b \Rightarrow d|c$.
Note that:
gcd$(a,0) = a$
gcd$(0,0)$ is not defined
gcd$(a,b) =$ gcd$(-a,b) =$ gcd$(a,-b) =$ gcd$(-a,-b) =$ gcd$(|a|,|b|)$
For any two integers $a$ and $b$, we carry out the following series of computations to find gcd$(a,b)$:
Since the $r_i$ form a strictly decreasing sequence, the algorithm must eventually stop. It can be proved that gcd$(a,b) =$ gcd$(b,r_1) =$ gcd$(r_1,r_2) = \cdots =$ gcd$(r_{k-1},r_k) = r_k$.
The pseudocode for Euclid’s algorithm is as follows:
gcd$(a,b)$
The number of steps $n$ required to complete Euclid’s algorithm in this form is less than $\lfloor{3}$ln(min{$a,b$})$\rfloor$.
If $d =$ gcd$(a,b)$, then there exists integers $s$ and $t$ (called the multipliers of $a$ and $b$ respectively) such that $as + bt = d$.
As a corollary of the last statement in the previous section, if gcd$(a,b) = 1$, then $s$ and $t$ are such that $as + bt = 1$. Therefore, $as = 1$ (mod $b$), i.e., $s$ is the multiplicative inverse of $a$ in the group $Z_b$. If $b$ is prime, then $s$ is the multiplicative inverse of $a$ in the field $GF(b)$.
Euler’s extended algorithm yields the multiplicative inverse of $a$ mod $b$. To describe it, we first rearrange the equations in Euclid’s algorithm:
Hence, for all $i \geq 1$, we can see that the relation $r_{i+1} = r_{i-1} - q_ir_i$ holds. We will augment the equations with the sequences $s_i$ and $t_i$ as follows:
We claim that $s_i$ and $t_i$ are such that $r_i = as_i + bt_i$. This can be proved inductively:
Base. $as_0 + bt_0 = a \cdot 1 + b \cdot 0 = a = r_0$ and $as_1 + bt_1 = a \cdot 0 + b \cdot 1 = b = r_1$.
Inductive Step. Suppose that $r_i = as_i + bt_i$ holds for all $i < k$. Now,
Hence, if $r_k =$ gcd$(a,b)$, then $s_k$ is the multiplicative inverse of $a$ mod $b$.
The pseudocode for Euclid’s extended algorithm is as follows:
inverse$(a,b)$
At the end, $B_3 =$ gcd$(a,b)$, and $aB_2 + bA_2 = 1$.
A polynomial $f(x)$ over a ring $R$ is defined as a formal expression of the form $f(x) = a_0 + a_1x + a_2x^2 + \cdots + a_nx^n$, where $a_i \in R$, $i = 0, 1, … , n$, and $a_n \neq 0$.
The highest exponent of $x$ is called the degree of $f(x)$, denoted as deg $f = n$. $x$ is called the indeterminate of $f$.
The set of all polynomials over $R$ also forms a ring, under the operations of R and following the laws of exponents for $x$. This ring is called the polynomial ring over $R$, and is denoted by $R[X]$ (if $x$ is the indeterminate).
A polynomial $f$ of degree $> 0$ over a field $K$ is said to be irreducible iff there do not exist polynomials $g, h \in K[X]$ such that deg $g > 0$, deg $h > 0$, and $f(x) = g(x) \cdot h(x)$.
Two equivalent statements of the above definition are: