Arithmetic Modulo
Division
If and are integers with then divides , written , if there exists an integer such that . Following this base theorem, we can extrapolate the following facts:
- If and then
- If then
- If and then
The algorithm
If is an integer and is a positive integer, then there are are unique integers and with such that:
Where is called the divisor, is called the quotient and is called the remainder.
Modulo relation
If and are integers and is a positive integer, then is congruent to modulo . This can also be written as , iff .
Congruence is an equivalence relation on integers.
Another rule is iff there is an integer such that .
If and then and .
Primes
A positive integer is called prime iff the only positive factors of are and . Otherwise, it is called composite.
Every positive integer greater than can be written uniquely as a prime or as the product of its prime factors, written in order of nondecreasing size. The uniqueness means that every positive integer has only one prime decomposition.
There are infinitely many primes, as can be proved by contradiction of the statement above.
Greatest common divisor
Let . The largest integer such that and is called the greatest common divisor of and , written as .
The integers and are coprime if . Meaning they have no positive integer common factors other than .
Prime factorisation
Suppose that the prime factorisation of and are:
Where each exponent is a nonnegative integer. Then:
This number would clearly divide and . No larger number can divide and . Factorisation is a very inefficient method since the factorisations must be computed.
Euclidean algorithm
This is another method of computing the gcd which uses recursion.
gcd(x,y):
if y = 0
return (x)
else
return gcd(y,(x mod y))
This logic uses facts covered earlier in this topic to draw together if and where and are integers. Then it follows that:
Linear combinations
If and are positive integers, then there exist integers and such that . This is called Bézout’s theorem.
This can be proved using the extended Euclidean algorithm.
e-gcd(x,y):
if y = 0
return (x,1,0)
else
(d,a,b) = e-gcd(y,(x mod y))
return ((d,b,a - ((x div y) * b)))