Definitions 2.1
Definition 2.2 Given two integers x and y, y divides x (y is a divisor of x) if there exists an integer z such that x = z.y.
Definition 2.3 Given two integers x and y, with y > 0, there exist two integers q (the quotient) and r (the remainder) such that
It can be proved that q and r are unique. Then (notation)
An alternative definition is the following.
Definition 2.4 (Integer Division) Given two integers x and y, with y > 0, there exist two integers q (the quotient) and r (the remainder) such that
It can be proved that q and r are unique. Then (notation)
Examples 2.1
Definitions 2.5
Notation: z = gcd(x, y).
Given two natural numbers x and y, the Euclidean algorithm for natural numbers computes gcd(x, y). It is based on a series of integer divisions:
Observe that any divider of r(i − 1) and r(i) is also a divider of r(i) and r(i + 1) so that
Initially,
Then compute
where r(1) > r(2) … > r(n) = 0 and gcd(r(i − 1), r(i)) = gcd(r(i), r(i + 1)), so that
Example 2.2 Let r(0) = x = 8580; r(1) = y = 4070;
Then gcd(8580,4070) = 110.
In the extended Euclidean algorithm a series of coefficients b(i) and c(i) are calculated in parallel with the computation of r(0), r(1), r(2), … , r(n):
It can be demonstrated by induction that
In particular,
In conclusion, the extended Euclidean algorithm expresses the greatest common divisor z of two natural numbers x and y as a linear combination of x and y, that is,
Algorithm 2.1 Extended Euclidean Algorithm
if x=0 then z:=y; b:=0; c:=1; elsif y=0 then z:=x; b:=1; c:=0; else r_i:=x; r_iplus1:=y; b_i:=1; c_i:=0; b_iplus1:=0; c_iplus1:=1; while r_iplus1>0 loop q:=r_i/r_iplus1; r_iplus2:=r_i mod r_iplus1; b_iplus2:=b_i-b_iplus1*q; c_iplus2:=c_i-c_iplus1*q; r_i:=r_iplus1; r_iplus1:=r_iplus2; b_i:=b_iplus1; b_iplus1:=b_iplus2; c_i:=c_iplus1; c_iplus1:= c_iplus2; end loop; z:=r_i; b:=b_i; c:=c_i; end if;
Example 2.3 Let ri = x = 230490; ri+1 = y = 43290; bi = ci+1 = 1; bi+1 = ci = 0.
Definition 2.6 Given two integers x and y, and a positive integer n, x is congruent to y modulo n if n divides the difference (x − y).
Notation:
Property 2.1 (Basic Properties of Congruences)
From Properties 2.1(1 and 2), it can be seen that the mod n congruence relation partitions Z into n equivalence classes. Each equivalence class contains exactly one element of the set {0, 1, 2, …, n − 1}, namely, the common value (x mod n) for all elements x of the class. Furthermore, according to Property 2.1(3), the addition, subtraction, and multiplication of congruence classes can be defined. As a matter of fact, the set of equivalence classes is isomorphic to
where the addition, the subtraction, and the multiplication are defined by
Definition 2.7 Given two elements x and y of Zn such that x.y = 1, then y is said to be the multiplicative inverse of x. If such an inverse exists, it is unique.
Notation:
Property 2.2 x has a multiplicative inverse if and only if gcd(x, n) = 1.
Proof If x.y = 1 mod n, then x.y = q.n + 1 so that any divisor of x and n is also a divisor of 1. Thus gcd(x, n) = 1.
If gcd(x, n) = 1, then (relation (2.1)) there exist b and c such that 1 = b.x + c.n, so that x−1 = b.
More generally, we have the following.
Properties 2.3
Proof
Observe that if k < g and x0 < (n/g), then xk ≤ (n/g) − 1 + (g − 1).(n/g) = n − 1.
Properties 2.4 (Chinese Remainder Theorem) Consider s pairwise relatively prime integers m1, m2, …, ms whose product is equal to M. Then the system
has a unique solution N within ZM (|a|m stands for a mod m):
where
The ri are called residues modulo mi.
Proof In order to compute a solution of system (2.3) observe that every mi is relatively prime with every mj (j ≠ i) so that every mj is relatively prime with = M/mj. Then has a multiplicative inverse and
is obviously a solution. The uniqueness is deduced from the fact that different systems have different solutions, and that there are exactly as many different systems as elements in ZM.
The computation of ()−1mod mi can be performed with the extended Euclidean algorithm: as mi is relatively prime with M/mj, the algorithm generates b and c such that
and
Garner's algorithm 2.2 ([GAR1959], [MEN1996]) computes N using a technique slightly different from the straight computation of (2.4). It computes first the mixed-radix digits within a preliminary step of a procedure step computing the base-B digits through a mixed-radix to base-B conversion (see mixed-radix system—Chapter 3).
A procedure inversion_step using the Euclidean algorithm to compute (mj)−1 mod mi is first defined as
procedure inversion_step (m(j), m(i): in natural; invm(j): out natural);
Algorithm 2.2 Garner's Algorithm
Assume N is given, according to (2.3), by its set of residues ri = N mod mi:
for i in 2..s loop c(i):=1; for j in 1..(i-1) loop inversion_step (m(j), m(i), invm(j)); c(i):=invm(j)*c(i) mod m(i); end loop; end loop; u:=r(1); x:=u; b(1):=1; for i in 2..s loop b(i):=b(i-1)*m(i-1); end loop; for i in 2..s loop u:=(r(i) 2 x)*c(i) mod m(i); x:=x+u*b(i); end loop;
Examples 2.4
while the Euclidean algorithm is used to compute
Formula (2.4) yields
The second loop computes the weights b(j) as
The third loop finally computes x as
Observe that the first two loops are independent and therefore may be computed in parallel. Moreover, if the modulus system is fixed, the c(i) and b(i) are computed once then stored for further use.
Definitions 2.8
According to Property 2.2, is the set of invertible elements of Zn. In particular, if p is a prime number then
Properties 2.5 (Fermat's Little Theorem) Let p be a prime.. Any integer x satisfies xp ≡ x (mod p), and any integer x not divisible by p satisfies xp−1 ≡ 1 (mod p).
Proof If x is not divisible by p and if i..x ≡ j.x (mod p), that is, (i − j).x = q.p, then i ≡ j (mod p). Thus
as the p − 1 above multiples of x are distinct and nonzero, they must be congruent to 1, 2, 3, … , p − 1 in some order.
So
or
As p does not divide (p − 1)!,
If x is divisible by p, then xp ≡ x ≡ 0 (mod p).
Corollary 2.1 Let p be a prime.. If x is not divisible by p and if r ≡ s (mod p − 1), then
Proof Assume that r > s. Then r = q.(p − 1) + s and 1 ≡ 1q ≡ (xp−1)q ≡ xr−s (mod p), so that xr ≡ xs (mod p).
Definitions 2.9
Observe that if x is a generator then = {x1, x2, x3, … , xϕ(n)}.
Example 2.5
There are two generators: 3 and 5. For example,