04_5_Solving_Congruen
04_5_Solving_Congruen
Section 4.4
Section Summary
Linear Congruences
The Chinese Remainder Theorem
Computer Arithmetic with Large Integers
(not currently included in slides, see text)
Fermat’s Little Theorem
Pseudoprimes
Primitive Roots and Discrete Logarithms
Linear Congruences
ax ≡ b( mod m),
Definition: A congruence of the form
= 1.Backwards:
Solution: First use the Euclidian algorithm to
show that gcd(101,4620)
42620 = 45∙101 + 1 = 3 − 1∙2
Working
modulo 42620
Using Inverses to Solve Congruences
We can solve the congruence ax≡ b( mod m) by
4( mod 7).
Solution: We found that −2 is an inverse of 3 modulo 7
by −2 giving
(two slides back). We multiply both sides of the congruence
−2 ∙ 3x ≡ −2 ∙ 4(mod 7).
Because −6 ≡ 1 (mod 7) and −8 ≡ 6 (mod 7), it follows
that if x is a solution, then x ≡ −8 ≡ 6 (mod 7)
We need to determine if every x with x ≡ 6 (mod 7) is a
solution. Assume that x ≡ 6 (mod 7). By Theorem 5 of
Section 4.1, it follows that 3x ≡ 3 ∙ 6 = 18 ≡ 4( mod 7)
30. continued →
the solution. Showing that the solution is unique modulo m is Exercise
The Chinese Remainder Theorem
To construct a solution first let Mk=m/mk for k = 1,2,…,n and m = m1m2 ∙ ∙ ∙ mn.
x = a1 M1 y1 + a2 M2 y2 + ∙ ∙ ∙ + an Mn yn .
Form the sum
Note that because Mj ≡ 0 ( mod mk) whenever j ≠k , all terms except the kth term in this
sum are congruent to 0 modulo mk .
Because Mk yk ≡ 1 ( mod mk ), we see that x ≡ ak Mk yk ≡ ak( mod mk), for k = 1,2,…,n.
x ≡ a1 ( mod m1)
Hence, x is a simultaneous solution to the n congruences.
x ≡ a2 ( mod m2)
∙
∙
∙
x ≡ an ( mod mn)
The Chinese Remainder Theorem
Example: Consider the 3 congruences from Sun-Tsu’s problem:
x ≡ 2 ( mod 3), x ≡ 3 ( mod 5), x ≡ 2 ( mod 7).
Let m = 3∙ 5 ∙ 7 = 105, M1 = m/3 = 35, M3 = m/5 = 21,
M3 = m/7 = 15.
We see that
2 is an inverse of M
1 = 35 modulo 3 since 35 ∙ 2 ≡ 2 ∙ 2 ≡ 1 (mod 3)
Hence,
By Fermat’s little theorem, we know that 710 ≡ 1 (mod 11), and so (710 )k ≡
1 (mod 11), for every positive integer k. Therefore,
gcd(b,n) = 1.
There are composite integers n that pass all tests with bases b such that
Example: Let h(k) = k mod 111. This hashing function assigns the records of
Because this hashing function is onto, all memory locations are possible.
customers with social security numbers as keys to memory locations in the following
manner:
h(064212848) = 064212848 mod 111 = 14
h(037149212) = 037149212 mod 111 = 65
h(107405723) = 107405723 mod 111 = 14, but since location 14 is already occupied, the record is
assigned to the next available position, which is 15.
The hashing function is not one-to-one as there are many more possible keys than
memory locations. When more than one record is assigned to the same location, we say
a collision occurs. Here a collision has been resolved by assigning the record to the
first free location.
For collision resolution, we can use a linear probing function:
h(k,i) = (h(k) + i) mod m, where i runs from 0 to m − 1.
There are many other methods of handling with collisions. You may cover these in a
later CS course.
Pseudorandom Numbers
Randomly chosen numbers are needed for many purposes, including
computer simulations.
Pseudorandom numbers are not truly random since they are
generated by systematic methods.
The linear congruential method is one commonly used procedure for
generating pseudorandom numbers.
seed x0 = 3.
(UPCs). Usually these have 12 decimal digits, the last one being the check
Example: Retail products are identified by their Universal Product Codes
a. Suppose that the first 9 digits of the ISBN-10 are 007288008. What is the check digit?
digit 10.
Solution:
X10 ≡ 1∙0 + 2∙0 + 3∙7 + 4∙2 + 5∙8 + 6∙8 + 7∙ 0 + 8∙0 + 9∙8 (mod 11).
for the
a.
X10 ≡ 0 + 0 + 21 + 8 + 40 + 48 + 0 + 0 + 72 (mod 11).
X10 ≡ 189 ≡ 2 (mod 11). Hence, X10 = 2.
b. 1∙0 + 2∙8 + 3∙4 + 4∙9 + 5∙3 + 6∙0 + 7∙ 1 + 8∙4 + 9∙9 + 10∙10 =
0 + 16 + 12 + 36 + 15 + 0 + 7 + 32 + 81 + 100 = 299 ≡ 2 ≢ 0 (mod 11)
Hence, 084930149X is not a valid ISBN-10.
A single error is an error in one digit of an identification number and a transposition error is the
accidental interchanging of two digits. Both of these kinds of errors can be detected by the check
digit for ISBN-10. (see text for more details)