Euclidean Division
Let a∈Z and b∈Z be two integers with b=0. Then there is always another integer m∈Z and a natural number r∈N, with 0≤r<∣b∣ such that the following holds:
This decomposition of a given b is called Euclidean Division, where a is called the dividend, b is called the divisor, m is called the quotient and r is called the remainder. It can be shown that both the quotient and the remainder always exist and are unique, as long as the divisor is different from 0.
Notation: Suppose that the numbers a,b,m and r satisfy above equation. We can then use the following notation for the quotient and the remainder of the Euclidean Division as follows:
We also say that an integer a is divisible by another integer b if a mod b=0 holds. In this case, we write b∣a, and call the integer a div b the cofactor of b in a.
The Euclidean Algorithm
The greatest common divisor of two non-zero integers a and b is defined as the largest non-zero natural number d such that d divides both a and b, that is, d∣a as well as d∣b are true. We use the notation gcd(a,b):=d for this number. Since the natural number 1 divides any other integer, 1 is always a common divisor of any two non-zero integers, but it is not necessarily the greatest.
A common method for computing the greatest common divisor is the so-called Euclidean Algorithm:
def gcd(a, b):
(r, rr) = (a, b)
while r % rr != 0:
(r, rr) = (rr, r % rr)
return rrSage example:
Complexity: O(logmin(a,b))
The Extended Euclidean Algorithm
The Extended Euclidean Algorithm is a method for calculating the greatest common divisor of two natural numbers a and b∈N, as well as two additional integers s,t∈Z, such that the following equation holds:
Sage example:
Complexity: O(logmin(a,b))
Last updated