Let m>1 be the modulus, an integer
The set of all integers congruent to amodm is called the congruence class of a modulo m
It is denoted as [a]m
Definition
The set of all congruence classes modulo m is denoted Z/mZ (read Z mod m)
There are some elements for which there exists a multiplicative inverse
[a]m[b]m=[b]m[a]m=[1]m
Which is denoted as ([a]m)−1, if it is unique and exists
Theorem
In Z/mZ, we have the equivalent statements:
[a]m has the inverse
For all [b]m[a]mx=[b]m has a unique solution
There exists [b]m such that [a]mx=[b]m has a unique solution
Theorem
Let m>1 be an integer
The element [a]m∈Z/mZ has a unique multiplicative inverse ⇐> gcd(a,m)=1
Theorem
If ρ is prime, all elements of Z/ρZ except [0]ρ have a multiplicative inverse
Euclid and Bézout
Theorem (Euclid)
Let a,b be non-zero integers. Then for k
gcd(a,b)=gcd(b,a−kb)
This means that we can make a simple gcd algorithm:
Algorithm
fn gcd(a: i32, b: i32) -> i32 { return if a < b { gcd(b, a) } else if b == 0 { a } else { gcd(b, a % b) }}
Theorem (Bézout)
Let a and b be integers, =0
There are integers u and v such that
gcd(a,b)=au+bv
With that, we can draw another algorithm:
Algorithm
fn euclid(a: i32, b: i32) -> (i32, i32, i32) { return if a < b { euclid(b, a) } else if b == 0 { (1, 0, a) } else { let q: i32 = a / b; let r: i32 = a % b; let (u, v, d) = euclid(b, r); (v, u - v * q, d) }}
Corollary
gcd(a,m)=1⇐> there exists integers u and v s.t au+mv=1