You are on page 1of 175

Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Linear Congruences

Bernd Schröder

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Introduction

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Introduction
1. Linear equations, that is, equations of the form ax = b are
the simplest type of equation we can encounter.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Introduction
1. Linear equations, that is, equations of the form ax = b are
the simplest type of equation we can encounter.
2. In this presentation, we will consider what happens when
equality is replaced with congruence modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Introduction
1. Linear equations, that is, equations of the form ax = b are
the simplest type of equation we can encounter.
2. In this presentation, we will consider what happens when
equality is replaced with congruence modulo m.
3. We will also see how the solution of multiple very simple
equations of this type leads to the Chinese Remainder
Theorem

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Introduction
1. Linear equations, that is, equations of the form ax = b are
the simplest type of equation we can encounter.
2. In this presentation, we will consider what happens when
equality is replaced with congruence modulo m.
3. We will also see how the solution of multiple very simple
equations of this type leads to the Chinese Remainder
Theorem, which is important because it paves the way for
efficiently working with large numbers.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Introduction
1. Linear equations, that is, equations of the form ax = b are
the simplest type of equation we can encounter.
2. In this presentation, we will consider what happens when
equality is replaced with congruence modulo m.
3. We will also see how the solution of multiple very simple
equations of this type leads to the Chinese Remainder
Theorem, which is important because it paves the way for
efficiently working with large numbers.
4. We will conclude with some results about numbers of the
form 2n − 1, because these numbers are often used as the
moduli in computer arithmetics.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.”

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.”

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db . Then (a0 , m) = 1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db . Then (a0 , m) = 1, so, by earlier theorem,
a0 · 1 − b0 , . . . , a0 · m − b0 is a complete set of residues modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db . Then (a0 , m) = 1, so, by earlier theorem,
a0 · 1 − b0 , . . . , a0 · m − b0 is a complete set of residues modulo m.
Hence, there is a k, so that a0 k − b0 ≡ 0 (mod m).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db . Then (a0 , m) = 1, so, by earlier theorem,
a0 · 1 − b0 , . . . , a0 · m − b0 is a complete set of residues modulo m.
Hence, there is a k, so that a0 k − b0 ≡ 0 (mod m). But then
ak − b ≡ (a0 k − b0 )d

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db . Then (a0 , m) = 1, so, by earlier theorem,
a0 · 1 − b0 , . . . , a0 · m − b0 is a complete set of residues modulo m.
Hence, there is a k, so that a0 k − b0 ≡ 0 (mod m). But then
ak − b ≡ (a0 k − b0 )d ≡ 0 · d

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db . Then (a0 , m) = 1, so, by earlier theorem,
a0 · 1 − b0 , . . . , a0 · m − b0 is a complete set of residues modulo m.
Hence, there is a k, so that a0 k − b0 ≡ 0 (mod m). But then
ak − b ≡ (a0 k − b0 )d ≡ 0 · d ≡ 0

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let m ∈ N, let a, b be integers and let d := (a, m).


Then the congruence ax ≡ b (mod m) has no solutions iff d - b.
In case d|b, the congruence has exactly d solutions that are
pairwise incongruent modulo m.

Proof. First note that d|ax for all x ∈ Z.


“⇐.” If d - b, then d - ax − b for all x ∈ Z. Because m is a
multiple of d, this implies that m - ax − b for all x ∈ Z. That is,
when d - b, the congruence ax ≡ b (mod m) has no solutions.
“⇒.” We prove the contrapositive, so let d|b. Let a0 := da and let
b0 := db . Then (a0 , m) = 1, so, by earlier theorem,
a0 · 1 − b0 , . . . , a0 · m − b0 is a complete set of residues modulo m.
Hence, there is a k, so that a0 k − b0 ≡ 0 (mod m). But then
ak − b ≡ (a0 k − b0 )d ≡ 0 · d ≡ 0 (mod m).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 )

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 )

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0 , and with j − i ∈ {0, . . . , d − 1}
this number is not divisible by m unless it is zero.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0 , and with j − i ∈ {0, . . . , d − 1}
this number is not divisible by m unless it is zero.
On the other hand, for any n ∈ Z, there are a q ∈ Z and a
j ∈ {0, . . . , d − 1} so that n = qd + j

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0 , and with j − i ∈ {0, . . . , d − 1}
this number is not divisible by m unless it is zero.
On the other hand, for any n ∈ Z, there are a q ∈ Z and a
j ∈ {0, . . . , d − 1} so that n = qd + j and then
(k + jm0 ) − (k + nm0 )

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0 , and with j − i ∈ {0, . . . , d − 1}
this number is not divisible by m unless it is zero.
On the other hand, for any n ∈ Z, there are a q ∈ Z and a
j ∈ {0, . . . , d − 1} so that n = qd + j and then
(k + jm0 ) − (k + nm0 ) = jm0 − qdm0 − jm0

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0 , and with j − i ∈ {0, . . . , d − 1}
this number is not divisible by m unless it is zero.
On the other hand, for any n ∈ Z, there are a q ∈ Z and a
j ∈ {0, . . . , d − 1} so that n = qd + j and then
(k + jm0 ) − (k + nm0 ) = jm0 − qdm0 − jm0 = −qm

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0 , and with j − i ∈ {0, . . . , d − 1}
this number is not divisible by m unless it is zero.
On the other hand, for any n ∈ Z, there are a q ∈ Z and a
j ∈ {0, . . . , d − 1} so that n = qd + j and then
(k + jm0 ) − (k + nm0 ) = jm0 − qdm0 − jm0 = −qm, which is
divisible by m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Now let m0 := md . With k from above so that


ak − b ≡ 0 (mod m), any k + nm0 is a solution of
ax ≡ b (mod m), because
a(k + nm0 ) = ak + a0 dnm0 = ak + a0 nm ≡ ak ≡ b (mod m). For
i, j ∈ {0, . . . , d − 1}, these solutions are pairwise incongruent
modulo m, because, for i ≤ j, we have
(k + jm0 ) − (k + im0 ) = (j − i)m0 , and with j − i ∈ {0, . . . , d − 1}
this number is not divisible by m unless it is zero.
On the other hand, for any n ∈ Z, there are a q ∈ Z and a
j ∈ {0, . . . , d − 1} so that n = qd + j and then
(k + jm0 ) − (k + nm0 ) = jm0 − qdm0 − jm0 = −qm, which is
divisible by m. So all numbers of the form k + nm0 are
congruent to a number k + jm0 with j ∈ {0, . . . , d − 1}.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr = ak + a0 nm + a0 dr

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr = ak + a0 nm + a0 dr ≡
ak + a0 dr

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr = ak + a0 nm + a0 dr ≡
ak + a0 dr ≡ b + a0 dr

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr = ak + a0 nm + a0 dr ≡
ak + a0 dr ≡ b + a0 dr 6≡ b

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr = ak + a0 nm + a0 dr ≡
ak + a0 dr ≡ b + a0 dr 6≡ b (mod m).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr = ak + a0 nm + a0 dr ≡
ak + a0 dr ≡ b + a0 dr 6≡ b (mod m).
Hence, the numbers k + jm0 with j ∈ {0, . . . , d − 1} are all the
pairwise incongruent solutions modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (cont.). Finally, any number k + nm0 + r with


r ∈ {1, . . . , m0 − 1} is not a solution, because
a(k + nm0 + r) = ak + a0 dnm0 + a0 dr = ak + a0 nm + a0 dr ≡
ak + a0 dr ≡ b + a0 dr 6≡ b (mod m).
Hence, the numbers k + jm0 with j ∈ {0, . . . , d − 1} are all the
pairwise incongruent solutions modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Corollary.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Corollary. Let m ∈ N, let a, b be integers. If a and m are


relatively prime, then ax ≡ b (mod m) has a unique solution
modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Corollary. Let m ∈ N, let a, b be integers. If a and m are


relatively prime, then ax ≡ b (mod m) has a unique solution
modulo m.

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Corollary. Let m ∈ N, let a, b be integers. If a and m are


relatively prime, then ax ≡ b (mod m) has a unique solution
modulo m.

Proof. If (a, m) = 1, then d in the previous theorem is 1.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Corollary. Let m ∈ N, let a, b be integers. If a and m are


relatively prime, then ax ≡ b (mod m) has a unique solution
modulo m.

Proof. If (a, m) = 1, then d in the previous theorem is 1.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Corollary. Let m ∈ N, let a, b be integers. If a and m are


relatively prime, then ax ≡ b (mod m) has a unique solution
modulo m.

Proof. If (a, m) = 1, then d in the previous theorem is 1.

Definition.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Corollary. Let m ∈ N, let a, b be integers. If a and m are


relatively prime, then ax ≡ b (mod m) has a unique solution
modulo m.

Proof. If (a, m) = 1, then d in the previous theorem is 1.

Definition. Let m ∈ N, let a, b be integers. If a and m are


relatively prime, then a solution of ax ≡ 1 (mod m) is called an
inverse of a modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the congruence 215x ≡ 86 (mod 301).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the congruence 215x ≡ 86 (mod 301).

First note that (215, 301) = 43.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the congruence 215x ≡ 86 (mod 301).

First note that (215, 301) = 43. (Use Euclid’s Algorithm or go


back to the presentation on Euclid’s Algorithm, where we saw
that 43 = 3 · 215 + (−2) · 301.)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the congruence 215x ≡ 86 (mod 301).

First note that (215, 301) = 43. (Use Euclid’s Algorithm or go


back to the presentation on Euclid’s Algorithm, where we saw
that 43 = 3 · 215 + (−2) · 301.) Because 43 | 86, there is a
solution.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the congruence 215x ≡ 86 (mod 301).

First note that (215, 301) = 43. (Use Euclid’s Algorithm or go


back to the presentation on Euclid’s Algorithm, where we saw
that 43 = 3 · 215 + (−2) · 301.) Because 43 | 86, there is a
solution. The congruence 5k ≡ 2 (mod 301) is solved by
k = 181.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the congruence 215x ≡ 86 (mod 301).

First note that (215, 301) = 43. (Use Euclid’s Algorithm or go


back to the presentation on Euclid’s Algorithm, where we saw
that 43 = 3 · 215 + (−2) · 301.) Because 43 | 86, there is a
solution. The congruence 5k ≡ 2 (mod 301) is solved by
k = 181. So, with m0 = 30143 = 7, the numbers
0
k + jm = 181 + 7j, j = 0, . . . , 42 are the solutions that are
pairwise incongruent modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the congruence 215x ≡ 86 (mod 301).

First note that (215, 301) = 43. (Use Euclid’s Algorithm or go


back to the presentation on Euclid’s Algorithm, where we saw
that 43 = 3 · 215 + (−2) · 301.) Because 43 | 86, there is a
solution. The congruence 5k ≡ 2 (mod 301) is solved by
k = 181. So, with m0 = 30143 = 7, the numbers
0
k + jm = 181 + 7j, j = 0, . . . , 42 are the solutions that are
pairwise incongruent modulo m.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


direction “⇒.”

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


direction “⇒.” Let a ∈ {0, . . . , p − 1} be so that a2 ≡ 1 (mod p).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


2
direction
“⇒.”
2
 a ∈ {0, . . . , p − 1} be so that a ≡ 1 (mod p).
Let
Then p a − 1 = (a + 1)(a − 1)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


2
direction
“⇒.”
2
 a ∈ {0, . . . , p − 1} be so that a ≡ 1 (mod p).
Let
Then p a − 1 = (a + 1)(a − 1), which means p|(a + 1) or
p|(a − 1).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


2
direction
“⇒.”
2
 a ∈ {0, . . . , p − 1} be so that a ≡ 1 (mod p).
Let
Then p a − 1 = (a + 1)(a − 1), which means p|(a + 1) or
p|(a − 1). Because p is prime, this is only possible for
a + 1 ∈ {0, p} or a − 1 ∈ {0, p}.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


2
direction
“⇒.”
2
 a ∈ {0, . . . , p − 1} be so that a ≡ 1 (mod p).
Let
Then p a − 1 = (a + 1)(a − 1), which means p|(a + 1) or
p|(a − 1). Because p is prime, this is only possible for
a + 1 ∈ {0, p} or a − 1 ∈ {0, p}. If a + 1 ∈ {0, p}, then
a ≡ −1 (mod p).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


2
direction
“⇒.”
2
 a ∈ {0, . . . , p − 1} be so that a ≡ 1 (mod p).
Let
Then p a − 1 = (a + 1)(a − 1), which means p|(a + 1) or
p|(a − 1). Because p is prime, this is only possible for
a + 1 ∈ {0, p} or a − 1 ∈ {0, p}. If a + 1 ∈ {0, p}, then
a ≡ −1 (mod p). If a − 1 ∈ {0, p}, then a ≡ 1 (mod p).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let p be a prime number. Then an integer a is its


own inverse modulo p iff a ≡ 1 (mod p) or a ≡ −1 (mod p).

Proof. The direction “⇐” is trivial, so we focus on proving the


2
direction
“⇒.”
2
 a ∈ {0, . . . , p − 1} be so that a ≡ 1 (mod p).
Let
Then p a − 1 = (a + 1)(a − 1), which means p|(a + 1) or
p|(a − 1). Because p is prime, this is only possible for
a + 1 ∈ {0, p} or a − 1 ∈ {0, p}. If a + 1 ∈ {0, p}, then
a ≡ −1 (mod p). If a − 1 ∈ {0, p}, then a ≡ 1 (mod p).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let k, n ∈ N be relatively prime and let a, b be


integers. Then a ≡ b (mod k) and a ≡ b (mod n) implies
a ≡ b (mod kn).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let k, n ∈ N be relatively prime and let a, b be


integers. Then a ≡ b (mod k) and a ≡ b (mod n) implies
a ≡ b (mod kn).

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let k, n ∈ N be relatively prime and let a, b be


integers. Then a ≡ b (mod k) and a ≡ b (mod n) implies
a ≡ b (mod kn).

Proof. a ≡ b (mod k) and a ≡ b (mod n)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let k, n ∈ N be relatively prime and let a, b be


integers. Then a ≡ b (mod k) and a ≡ b (mod n) implies
a ≡ b (mod kn).

Proof. a ≡ b (mod k) and a ≡ b (mod n) implies k|(b − a) and


n|(b − a).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let k, n ∈ N be relatively prime and let a, b be


integers. Then a ≡ b (mod k) and a ≡ b (mod n) implies
a ≡ b (mod kn).

Proof. a ≡ b (mod k) and a ≡ b (mod n) implies k|(b − a) and


n|(b − a). Because k and n are relatively prime, this implies that
kn|(b − a)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let k, n ∈ N be relatively prime and let a, b be


integers. Then a ≡ b (mod k) and a ≡ b (mod n) implies
a ≡ b (mod kn).

Proof. a ≡ b (mod k) and a ≡ b (mod n) implies k|(b − a) and


n|(b − a). Because k and n are relatively prime, this implies that
kn|(b − a), that is, a ≡ b (mod kn).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let k, n ∈ N be relatively prime and let a, b be


integers. Then a ≡ b (mod k) and a ≡ b (mod n) implies
a ≡ b (mod kn).

Proof. a ≡ b (mod k) and a ≡ b (mod n) implies k|(b − a) and


n|(b − a). Because k and n are relatively prime, this implies that
kn|(b − a), that is, a ≡ b (mod kn).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Chinese Remainder Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Chinese Remainder Theorem. Let m1 , . . . , mk ∈ N


be pairwise relatively prime. Then for any integers a1 , . . . , ak
there is an integer x so that x ≡ aj (mod mj ) holds for
j = 1, . . . , k.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Chinese Remainder Theorem. Let m1 , . . . , mk ∈ N


be pairwise relatively prime. Then for any integers a1 , . . . , ak
there is an integer x so that x ≡ aj (mod mj ) holds for
j = 1, . . . , k. Moreover, this number x is unique modulo
m1 · · · mk .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 )

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).
Now consider the general case.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).
Now consider the general case. Because the mj are pairwise
relatively prime, for each j, there is a yj so that

∏i6=j mi yj ≡ 1 (mod mj ).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).
Now consider the general case. Because the mj are pairwise
relatively prime, for each j, there is a yj so that
 k
∏i6=j mi yj ≡ 1 (mod mj ). Now let x = ∑ aj ∏ mi yj .
j=1 i6=j

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).
Now consider the general case. Because the mj are pairwise
relatively prime, for each j, there is a yj so that
 k
∏i6=j mi yj ≡ 1 (mod mj ). Now let x = ∑ aj ∏ mi yj . Then, for
j=1 i6=j
each n ∈ {1, . . . , k}, we have
k
x = ∑ aj ∏ miyj
j=1 i6=j

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).
Now consider the general case. Because the mj are pairwise
relatively prime, for each j, there is a yj so that
 k
∏i6=j mi yj ≡ 1 (mod mj ). Now let x = ∑ aj ∏ mi yj . Then, for
j=1 i6=j
each n ∈ {1, . . . , k}, we have
k
x = ∑ aj ∏ miyj = an ∏ miyn + ∑ aj ∏ miyj
j=1 i6=j i6=n j6=n i6=j

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).
Now consider the general case. Because the mj are pairwise
relatively prime, for each j, there is a yj so that
 k
∏i6=j mi yj ≡ 1 (mod mj ). Now let x = ∑ aj ∏ mi yj . Then, for
j=1 i6=j
each n ∈ {1, . . . , k}, we have
k
x = ∑ aj ∏ miyj = an ∏ miyn + ∑ aj ∏ miyj
j=1 i6=j i6=n j6=n i6=j
≡ an · 1 + ∑ aj · 0 · yj
j6=n
Bernd Schröder Louisiana Tech University, College of Engineering and Science
Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof. First consider the case k = 2. Because m1 and m2 are


relatively prime, there are y1 , y2 so that m1 y2 ≡ 1 (mod m2 ) and
m2 y1 ≡ 1 (mod m1 ). Now let x = a1 m2 y1 + a2 m1 y2 . Then
x = a1 m2 y1 + a2 m1 y2 ≡ a1 · 1 + 0 (mod m1 ), and
x = a1 m2 y1 + a2 m1 y2 ≡ 0 + a2 · 1 (mod m2 ).
Now consider the general case. Because the mj are pairwise
relatively prime, for each j, there is a yj so that
 k
∏i6=j mi yj ≡ 1 (mod mj ). Now let x = ∑ aj ∏ mi yj . Then, for
j=1 i6=j
each n ∈ {1, . . . , k}, we have
k
x = ∑ aj ∏ miyj = an ∏ miyn + ∑ aj ∏ miyj
j=1 i6=j i6=n j6=n i6=j
≡ an · 1 + ∑ aj · 0 · yj ≡ an (mod mn )
j6=n
Bernd Schröder Louisiana Tech University, College of Engineering and Science
Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (concl.).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (concl.). For the uniqueness, note that if x and y are two
solutions

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (concl.). For the uniqueness, note that if x and y are two
solutions, then x ≡ aj ≡ y (mod mj )

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (concl.). For the uniqueness, note that if x and y are two
solutions, then x ≡ aj ≡ y (mod mj ), that is, mj |(x − y) for all j.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (concl.). For the uniqueness, note that if x and y are two
solutions, then x ≡ aj ≡ y (mod mj ), that is, mj |(x − y) for all j.
Because the mj are pairwise relatively prime, we conclude
∏kj=1 mj (x − y).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Proof (concl.). For the uniqueness, note that if x and y are two
solutions, then x ≡ aj ≡ y (mod mj ), that is, mj |(x − y) for all j.
Because the mj are pairwise relatively prime, we conclude
∏kj=1 mj (x − y).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8
So x :=

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8
So x := 1 · 63 · 2 + 4 · 45 · 5 + 2 · 35 · 8

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8
So x := 1 · 63 · 2 + 4 · 45 · 5 + 2 · 35 · 8 = 126 + 900 + 560

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8
So x := 1 · 63 · 2 + 4 · 45 · 5 + 2 · 35 · 8 = 126 + 900 + 560 =
1586

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8
So x := 1 · 63 · 2 + 4 · 45 · 5 + 2 · 35 · 8 = 126 + 900 + 560 =
1586 ≡ 11 (mod 315)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8
So x := 1 · 63 · 2 + 4 · 45 · 5 + 2 · 35 · 8 = 126 + 900 + 560 =
1586 ≡ 11 (mod 315) is the solution.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Example. Solve the system of congruences


x ≡ 1 (mod 5)
x ≡ 4 (mod 7)
x ≡ 2 (mod 9)

7 · 9 · y1 ≡ 1 (mod 5) y1 = 2
5 · 9 · y2 ≡ 1 (mod 7) y2 = 5
5 · 7 · y3 ≡ 1 (mod 9) y3 = 8
So x := 1 · 63 · 2 + 4 · 45 · 5 + 2 · 35 · 8 = 126 + 900 + 560 =
1586 ≡ 11 (mod 315) is the solution.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Arithmetic With Large Integers

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Arithmetic With Large Integers


Let m1 , . . . , mk be pairwise relatively prime.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Arithmetic With Large Integers


Let m1 , . . . , mk be pairwise relatively prime.
1. Every integer between 0 and m1 · · · mk − 1 is unique
modulo m1 · · · mk .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Arithmetic With Large Integers


Let m1 , . . . , mk be pairwise relatively prime.
1. Every integer between 0 and m1 · · · mk − 1 is unique
modulo m1 · · · mk .
2. So to uniquely represent integers up to size N with smaller
integers, find pairwise relatively prime integers m1 , . . . , mk
whose product exceeds N.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Arithmetic With Large Integers


Let m1 , . . . , mk be pairwise relatively prime.
1. Every integer between 0 and m1 · · · mk − 1 is unique
modulo m1 · · · mk .
2. So to uniquely represent integers up to size N with smaller
integers, find pairwise relatively prime integers m1 , . . . , mk
whose product exceeds N.
3. Numbers x up to N are now represented by the tuple
(x1 , . . . , xk ) of their least nonnegative residues modulo the
mj .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Arithmetic With Large Integers


Let m1 , . . . , mk be pairwise relatively prime.
1. Every integer between 0 and m1 · · · mk − 1 is unique
modulo m1 · · · mk .
2. So to uniquely represent integers up to size N with smaller
integers, find pairwise relatively prime integers m1 , . . . , mk
whose product exceeds N.
3. Numbers x up to N are now represented by the tuple
(x1 , . . . , xk ) of their least nonnegative residues modulo the
mj .
4. Arithmetic is done componentwise.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Arithmetic With Large Integers


Let m1 , . . . , mk be pairwise relatively prime.
1. Every integer between 0 and m1 · · · mk − 1 is unique
modulo m1 · · · mk .
2. So to uniquely represent integers up to size N with smaller
integers, find pairwise relatively prime integers m1 , . . . , mk
whose product exceeds N.
3. Numbers x up to N are now represented by the tuple
(x1 , . . . , xk ) of their least nonnegative residues modulo the
mj .
4. Arithmetic is done componentwise. (On parallel
computers, these operations are done in parallel and thus
take the same amount of time as a regular operation. We
just need as many processors as we have residues.)

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Computer Arithmetic Modulo Numbers of the


Form 2m − 1 is Particularly Efficient

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Computer Arithmetic Modulo Numbers of the


Form 2m − 1 is Particularly Efficient
1. Store the number in the lowest m bits of a signed or
unsigned integer.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Computer Arithmetic Modulo Numbers of the


Form 2m − 1 is Particularly Efficient
1. Store the number in the lowest m bits of a signed or
unsigned integer.
2. Wrap around to zero when all lowest m bits are 1.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Computer Arithmetic Modulo Numbers of the


Form 2m − 1 is Particularly Efficient
1. Store the number in the lowest m bits of a signed or
unsigned integer.
2. Wrap around to zero when all lowest m bits are 1.
3. Carryovers are handled slightly differently than the default

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Computer Arithmetic Modulo Numbers of the


Form 2m − 1 is Particularly Efficient
1. Store the number in the lowest m bits of a signed or
unsigned integer.
2. Wrap around to zero when all lowest m bits are 1.
3. Carryovers are handled slightly differently than the default,
but this is still easier than using other moduli.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Computer Arithmetic Modulo Numbers of the


Form 2m − 1 is Particularly Efficient
1. Store the number in the lowest m bits of a signed or
unsigned integer.
2. Wrap around to zero when all lowest m bits are 1.
3. Carryovers are handled slightly differently than the default,
but this is still easier than using other moduli.
4. Working with moduli of the form 2n would be even easier,
but those are not relatively prime, and hence they are
useless as moduli for the Chinese Remainder Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Computer Arithmetic Modulo Numbers of the


Form 2m − 1 is Particularly Efficient
1. Store the number in the lowest m bits of a signed or
unsigned integer.
2. Wrap around to zero when all lowest m bits are 1.
3. Carryovers are handled slightly differently than the default,
but this is still easier than using other moduli.
4. Working with moduli of the form 2n would be even easier,
but those are not relatively prime, and hence they are
useless as moduli for the Chinese Remainder Theorem.
So we are interested in relatively prime numbers of the form
2n − 1, because they are the most efficient moduli that can be
used with the Chinese Remainder Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof. With a = qb + r we obtain


2a −1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof. With a = qb + r we obtain


2a −1 = 2qb+r −1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof. With a = qb + r we obtain


 q
a qb+r
2 −1 = 2 −1 = 2 2b −1
r

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof. With a = qb + r we obtain


 q
a
2 −1 = 2 qb+r
−1 = 2 2b −1 ≡ 2r (1)q −1
r

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof. With a = qb + r we obtain


 q
a
2 −1 = 2 qb+r
−1 = 2 2b −1 ≡ 2r (1)q −1 ≡ 2r −1
r

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof. With a = qb + r we obtain


 q  
a qb+r r b r q r b
2 −1 = 2 −1 = 2 2 −1 ≡ 2 (1) −1 ≡ 2 −1 mod 2 − 1 .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let a, b ∈ N and let r be the least positive residue of a


modulo b. The least positive residue of 2a − 1 modulo 2b − 1 is
2r − 1.

Proof. With a = qb + r we obtain


 q  
a qb+r r b r q r b
2 −1 = 2 −1 = 2 2 −1 ≡ 2 (1) −1 ≡ 2 −1 mod 2 − 1 .

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1 = q (2y − 1) + 2r − 1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1 = q (2y − 1) + 2r − 1, where (previous lemma) r is the
remainder of the division of x by y.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1 = q (2y − 1) + 2r − 1, where (previous lemma) r is the
remainder of the division of x by y. This means (inductively),
that the numbers in the Euclidean algorithm for 2x − 1 and
2y − 1 are of the form 2k + 1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1 = q (2y − 1) + 2r − 1, where (previous lemma) r is the
remainder of the division of x by y. This means (inductively),
that the numbers in the Euclidean algorithm for 2x − 1 and
2y − 1 are of the form 2k + 1 and the exponents are the numbers
we get in the Euclidean algorithm for x and y.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1 = q (2y − 1) + 2r − 1, where (previous lemma) r is the
remainder of the division of x by y. This means (inductively),
that the numbers in the Euclidean algorithm for 2x − 1 and
2y − 1 are of the form 2k + 1 and the exponents are the numbers
we get in the Euclidean algorithm for x and y. So the algorithm
stops at a positive integer n so that (2x − 1, 2y − 1) = 2n − 1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1 = q (2y − 1) + 2r − 1, where (previous lemma) r is the
remainder of the division of x by y. This means (inductively),
that the numbers in the Euclidean algorithm for 2x − 1 and
2y − 1 are of the form 2k + 1 and the exponents are the numbers
we get in the Euclidean algorithm for x and y. So the algorithm
stops at a positive integer n so that (2x − 1, 2y − 1) = 2n − 1 and
that number n is (x, y).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Lemma. Let x, y ∈ N. Then (2x − 1, 2y − 1) = 2(x,y) − 1.

Proof. Assuming x ≥ y, the first step in the Euclidean


Algorithm applied to 2x − 1 and 2y − 1 is
2x − 1 = q (2y − 1) + 2r − 1, where (previous lemma) r is the
remainder of the division of x by y. This means (inductively),
that the numbers in the Euclidean algorithm for 2x − 1 and
2y − 1 are of the form 2k + 1 and the exponents are the numbers
we get in the Euclidean algorithm for x and y. So the algorithm
stops at a positive integer n so that (2x − 1, 2y − 1) = 2n − 1 and
that number n is (x, y).

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof. By the preceding lemma, 2x − 1 and 2y − 1 are relatively


prime iff 1 = (2x − 1, 2y − 1) = 2(x,y) − 1.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof. By the preceding lemma, 2x − 1 and 2y − 1 are relatively


prime iff 1 = (2x − 1, 2y − 1) = 2(x,y) − 1. Now 2(x,y) − 1 = 1 iff

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof. By the preceding lemma, 2x − 1 and 2y − 1 are relatively


prime iff 1 = (2x − 1, 2y − 1) = 2(x,y) − 1. Now 2(x,y) − 1 = 1 iff
(x, y) = 1

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof. By the preceding lemma, 2x − 1 and 2y − 1 are relatively


prime iff 1 = (2x − 1, 2y − 1) = 2(x,y) − 1. Now 2(x,y) − 1 = 1 iff
(x, y) = 1, which is the case iff x and y are relatively prime.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof. By the preceding lemma, 2x − 1 and 2y − 1 are relatively


prime iff 1 = (2x − 1, 2y − 1) = 2(x,y) − 1. Now 2(x,y) − 1 = 1 iff
(x, y) = 1, which is the case iff x and y are relatively prime.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof. By the preceding lemma, 2x − 1 and 2y − 1 are relatively


prime iff 1 = (2x − 1, 2y − 1) = 2(x,y) − 1. Now 2(x,y) − 1 = 1 iff
(x, y) = 1, which is the case iff x and y are relatively prime.

So this result means that there are many reasonable numbers of


the form 2n − 1 that can be used in an implementation of an
arithmetic that relies on the Chinese Remainder Theorem.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences
Solving Linear Congruences Chinese Remainder Theorem Numbers 2n − 1

Theorem. Let x, y ∈ N. Then 2x − 1 and 2y − 1 are relatively


prime iff x and y are relatively prime.

Proof. By the preceding lemma, 2x − 1 and 2y − 1 are relatively


prime iff 1 = (2x − 1, 2y − 1) = 2(x,y) − 1. Now 2(x,y) − 1 = 1 iff
(x, y) = 1, which is the case iff x and y are relatively prime.

So this result means that there are many reasonable numbers of


the form 2n − 1 that can be used in an implementation of an
arithmetic that relies on the Chinese Remainder Theorem.

Neat exercise: Find a set of numbers nj , preferably all ≤ 64 that


can be used for an arithmetic that models 200 (decimal) place
arithmetic.

Bernd Schröder Louisiana Tech University, College of Engineering and Science


Linear Congruences

You might also like