01-Teoribilangan Slides

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 100

Number Theory

Adila A. Krisnadhi
Fakultas Ilmu Komputer, Universitas Indonesia

Version date: 2020-01-26 20:52:03+07:00


Reference: Rosen, Ed.8, Ch.4
Agenda

Divisibility and Modular Arithmetic

Integer Representations

Primes

Greatest Common Divisor (GCD) & Least Common Multiple (LCM)

Linear Congruences

2/71
Agenda

Divisibility and Modular Arithmetic

Integer Representations

Primes

Greatest Common Divisor (GCD) & Least Common Multiple (LCM)

Linear Congruences

3/71
Introduction

• Number theory: a branch of mathematics that studies integers, their


characteristics, operations, and further generalization derivable from them.
• Integer (basic) operations: addition, subtraction, multiplication, division
• The core part of number theory is called arithmetic.
• Applications: cryptography, hashing, digit error checking

4/71
Notation

• Set of (all) integers: Z = {. . . , −3, −2, −1, 0, 1, 2, 3, . . . }


• Set of (all) positive integers: Z+ = {1, 2, 3, . . . }
• Set of (all) negative integers: Z− = {. . . , −3, −2, −1}
• Set of natural numbers atau nonnegative integers: N = {0, 1, 2, 3, . . . }

5/71
Discussion

• What’s the difference between the divisions: 18/3 and 16/5?


• What makes division special for integers compared to addition, subtraction,
and multiplication?
• What is the relation between 3 and 18 in the context of division?
• What is the relation between 5 and 16 in the context of division?

6/71
Divisibility

Definition 1
Let a and b be two integers with a 6= 0.
We say that a divides b iff there exists an integer c such that b = ac. That is, a
divides b iff ab ∈ Z.
a | b denotes “a divides b”. Also, a6 | b denotes “a does not divide b”.
If a | b, then a is called a factor or divisor of b, and b is called a multiple of a.

7/71
Divsibility Examples

• Is 7 | 13?
• Is 3 | 12?
• If n and d are positive integers, how many positive integers are there that is
no greater than n and divisible by d?

8/71
Discussion
Can we generalize anything from the following facts?
• 13 | 65, 13 | 221, and 13 | 286
• 8 | −24, 8 | 32, and 8 | 56
• 11 | 44. So, 11 | −88, 11 | 88, 11 | 176, etc.
• 7 | 35, 35 | 245, and 7 | 245.
• 6 | 18, 6 | 24, and 6 | 102.

9/71
Theorem 2
Let a, b, c be integers with a 6= 0. Then,
(i) if a | b and a | c, then a | (b + c);

(ii) if a | b, then a | bd for every integer d;

(iii) if a | b and b | c, then a | c;

(iv) (generalization of part (i)) if a | b and a | c, then a | (mb + nc) for any two
integers m dan n.

Proof?

10/71
Discussion

• What happens when we divide 19 by 5, 12 by 4, or -13 by 7?


• From your answer for the above question, can you express 19 in terms of 5,
12 in terms of 4, and -13 in terms of 7?

11/71
Division algorithm, quotient, and remainder

The following theorem is often called division algorithm despite not exactly an
algorithm.
Theorem 3 (The Division Algorithm)
Let a, d be integers with d 6= 0. Then, there exists two unique integers q and r
with 0 ≤ r < d such that a = dq + r
In the above theorem,
• the integer q is called the quotient and written q = a div d
• the integer r is called remainder and written r = a mod d.
Note that r is never negative.

12/71
Divison algorithm: Examples

Give the quotient and remainder when:


• 111 is divided by 13;
• -13 is divided by 3.

13/71
Divisibility and mod operations
What is the relation between divisibility and mod?

14/71
Divisibility and mod operations
What is the relation between divisibility and mod?

Theorem 4
Let a and b be integers with a 6= 0. Then, a | b if and only if b mod a = 0.

Proof?

14/71
Modular congruences

Sometimes, we only care about the remainder of an integer division.


• What time is 100 hours from now?
• What day is 10000 days in the past?

15/71
Modular congruences

Sometimes, we only care about the remainder of an integer division.


• What time is 100 hours from now?
• What day is 10000 days in the past?

Definition 5
Let a, b, m be integers with m positive. Then, a ≡ b (mod m) iff m | (a − b).

• The notation a ≡ b (mod m) is called congruence and read “a is


congruent to b modulo m”. The integer m is called the modulus
• If a is not congruent to b modulo m, then we write a 6≡ b (mod m)
• What is the difference between a ≡ b (mod m) dan a mod m = b?

15/71
Relationship between mod dan mod

Fill in this table. Can you generalize anything from this?


a b m Is a ≡ b (mod m)? a mod m b mod m
7 12 5 Yes 2 2
3 14 7 No 3 0
-5 23 14 Yes 9 9
-7 -4 3 Yes 2 2
21 9 6 Yes 3 3
17 4 6 No 5 4

16/71
Relationship between mod dan mod

Theorem 6
Let a, b be integers and m a positive integer.
Then, a ≡ b (mod m) if and only if a mod m = b mod m.

That is, a ≡ b (mod m) if and only if a dan b have the same remainder when
divided by m.
Proof?

17/71
Modular congruence and division algorithm

Fill in the table:


a b m Is a ≡ b (mod m)? a = b + km (if possible)
7 12 5 Yes 7 = 12 + (−1)5
3 14 7
-5 23 14
-7 -4 3
21 9 6
17 4 6

18/71
Modular congruence and division algorithm

Theorem 7
Let m be a positive integer. Then, a ≡ b (mod m) if and only if there exists an
integer k such that a = b + km.
Proof?

19/71
Congruence classes
If we take 5 as the modulus,
• how many integers are congruent to 7? What are they?
• what integers are congruent to 6?

20/71
Congruence classes
If we take 5 as the modulus,
• how many integers are congruent to 7? What are they?
• what integers are congruent to 6?

Definition 8
Let a be an integer and m a positive integer. The congruence class of a
modulo m, written [a]m , is the set of all integers congruent to a modulo m.

Give all congruence classes modulo 3!

20/71
Modular addition and multiplication

Theorem 9
Let m be a positive integer.
Then, whenever a ≡ b (mod m) and c ≡ d (mod m) hold, then the following
also hold:
• a + c ≡ b + d (mod m), and
• ac ≡ bd (mod m).

Proof?
Give an application example of the above theorem!

21/71
Remarks

• Does ac ≡ bc (mod m) imply a ≡ b (mod m) ?

• If a ≡ b (mod m) dan c ≡ d (mod m), does ac ≡ bd (mod m) necessarily


hold?

22/71
Remarks

• Does ac ≡ bc (mod m) imply a ≡ b (mod m) ?


• No. For example, 2 · 4 ≡ 5 · 4 (mod 6), but 2 6≡ 5 (mod 6).
So, you cannot cross out the multiplier from both sides of congruences.
• If a ≡ b (mod m) dan c ≡ d (mod m), does ac ≡ bd (mod m) necessarily
hold?

22/71
Remarks

• Does ac ≡ bc (mod m) imply a ≡ b (mod m) ?


• No. For example, 2 · 4 ≡ 5 · 4 (mod 6), but 2 6≡ 5 (mod 6).
So, you cannot cross out the multiplier from both sides of congruences.
• If a ≡ b (mod m) dan c ≡ d (mod m), does ac ≡ bd (mod m) necessarily
hold?
• No. For example, 3 ≡ 8 (mod 5) and 6 ≡ 1 (mod 5), but
729 = 36 6≡ 81 = 8 (mod 5).
So, pair of congruent bases and congruent exponents do not make the result
of the exponentiation congruent.

22/71
Modulo addition and multiplication

Theorem 10
Let m be a positive integer and a, b integers. Then,
• (a + b) mod m = ((a mod m) + (b mod m)) mod m
• ab mod m = ((a mod m)(b mod m)) mod m.

Proof?

23/71
Example

Calculate (193 mod 31)4 mod 23?

24/71
Agenda

Divisibility and Modular Arithmetic

Integer Representations

Primes

Greatest Common Divisor (GCD) & Least Common Multiple (LCM)

Linear Congruences

25/71
Integer representation: Overview

• Representation depends on base of choice.


• Every positive integer b > 1 can be used of basis.
• A base-b representation employs b different symbols.
• Some commonly used bases:
• Base 10 (decimal) 10 symbols: 0, 1, . . . , 9
• Base 2 (binary) 2 symbols: 0, 1
• Base 8 (octal) 8 symbols: 0, 1, . . . , 7
• Base 16 (hexadecimal) 16 symbols: 0, 1, . . . , 9, A, B, . . . , F .

26/71
• Write the binary representation of 21
• Write the decimal representation (326)8

27/71
Integer representation

Theorem 11
Given an integer b > 1 as base, every positive integer n can be expressed
uniquely in the following form:

n = ak bk + ak−1 bk−1 + . . . a1 b + a0

where k, a0 , a1 , . . . , ak are nonnegative integers, 0 ≤ a0 , a1 , . . . , ak < b, and


ak 6= 0
We call the expression on the right-hand side of the equation in Theorem 11 the
base-b expansion of n.

28/71
Decimal to non-decimal conversion

Let n be a positive integer in a decimal representation. Conversion to base b can


be done using the following algorithm.
Algorithm 1 (Converting n to base b)
Input: n positive integer in a decimal representation, b an integer (b > 1).
q := n
k := 0
while q 6= 0
ak := q mod b
q := q div b
k := k + 1
return (ak−1 . . . a1 a0 )b base-b expansion of n.

29/71
Example

Convert 54321 to an octal expansion.

30/71
Example

Convert 54321 to an octal expansion.

54321 = 8 · 6790 + 1

30/71
Example

Convert 54321 to an octal expansion.

54321 = 8 · 6790 + 1
6790 = 8 · 848 + 6

30/71
Example

Convert 54321 to an octal expansion.

54321 = 8 · 6790 + 1
6790 = 8 · 848 + 6
848 = 8 · 106 + 0

30/71
Example

Convert 54321 to an octal expansion.

54321 = 8 · 6790 + 1
6790 = 8 · 848 + 6
848 = 8 · 106 + 0
106 = 8 · 13 + 2

30/71
Example

Convert 54321 to an octal expansion.

54321 = 8 · 6790 + 1
6790 = 8 · 848 + 6
848 = 8 · 106 + 0
106 = 8 · 13 + 2
13 = 8 · 1 + 5

30/71
Example

Convert 54321 to an octal expansion.

54321 = 8 · 6790 + 1
6790 = 8 · 848 + 6
848 = 8 · 106 + 0
106 = 8 · 13 + 2
13 = 8 · 1 + 5
1=8·0+1

30/71
Example

Convert 54321 to an octal expansion.

54321 = 8 · 6790 + 1
6790 = 8 · 848 + 6
848 = 8 · 106 + 0
106 = 8 · 13 + 2
13 = 8 · 1 + 5
1=8·0+1

Final result is (152061)8 .

30/71
Example

Convert 331771 to hexadecimal

31/71
Example

Convert 331771 to hexadecimal

331771 = 16 · 20735 + 11

31/71
Example

Convert 331771 to hexadecimal

331771 = 16 · 20735 + 11
20735 = 16 · 1295 + 15

31/71
Example

Convert 331771 to hexadecimal

331771 = 16 · 20735 + 11
20735 = 16 · 1295 + 15
1295 = 16 · 80 + 15

31/71
Example

Convert 331771 to hexadecimal

331771 = 16 · 20735 + 11
20735 = 16 · 1295 + 15
1295 = 16 · 80 + 15
80 = 16 · 5 + 0

31/71
Example

Convert 331771 to hexadecimal

331771 = 16 · 20735 + 11
20735 = 16 · 1295 + 15
1295 = 16 · 80 + 15
80 = 16 · 5 + 0
5 = 16 · 0 + 5

31/71
Example

Convert 331771 to hexadecimal

331771 = 16 · 20735 + 11
20735 = 16 · 1295 + 15
1295 = 16 · 80 + 15
80 = 16 · 5 + 0
5 = 16 · 0 + 5

The result is (50FFB)16 . Here, B dan F are the hexadecimal digit for 11 and 15,
resp.

31/71
Why does our base conversion work?

32/71
Conversion between binary, octal, and hexadecimal expansion
• Converting between two non-decimal expansion b1 dan b2
1 convert base-b1 expansion to a decimal expansion (Theorem 11);
2 convert the result into a base-b2 expansion (Algorithm 1).
• Rapid conversion between binary, octal and hexadecimal:
• 3 binary digits for 1 octal digit, and 4 binary digits for 1 hexadecimal
• proceed from right

(11111010111100)2 = 011 111 010 111 100 = (37274)8


38 78 28 78 48

= 0011 1110 1011 1100 = (3EBC)16


316 E16 B16 C16

(567)8 = (101 110 111)2


(D8A)16 = (1101 1000 1010)2
33/71
Floor and ceiling functions

• Floor function:
bxc = the largest integer less than or equal to x.
• Ceiling function:
dxe = the smallest integer greater than or equal to x.

Theorem 12
For integers a, d with d > 1,
• a div d = ad
 

• a mod d = a − d ad
 

Proof?

34/71
Modular exponentiation
In cryptography applications, we often need to calculate bn mod m rapidlly
without calculating bn first, for example, 3644 mod 645
Main idea:
• By Theorem 11, n can be written in binary as (ak−1 . . . a1 a0 )2 :
n = ak−1 · 2k−1 + · · · + a1 · 2 + a0
where a0 , . . . , ak−1 are either 0 atau 1.
• So, bn = bak−1 2k−1 +···+a1 ·2+a0 = bak−1 ·2k−1 · · · ba1 ·2 ba0
• If ai = 0 for some i, then bai ·2i = b0 = 1. So, it suffices to consider bai ·2i for
which ai 6= 0 in the above product. For example, for the case of 311 , we
note that 11 = (1011)2 = 1 · 23 + 0 · 22 + 1 · 21 + 1 · 20 = 8 + 2 + 1. Hence,
we only need to consider 23 , 21 , 20 .
• We perform exponentiation and multiplication while doing modulo operation
every time exponentiation and multiplication is done.
35/71
Modular exponentiation algorithm

Algorithm 2 (Calculating bn mod m)


Input: b integer, n = (ak−1 ak−2 . . . a1 a0 )2 , m positive integer.
x := 1
p := b mod m
for i := 0 to k − 1
if ai = 1 then x := (x · p) mod m
p := (p · p) mod m
return x x is equal to bn mod m.

36/71
Modular exponentiation example
Calculate 3644 mod 645.

37/71
Agenda

Divisibility and Modular Arithmetic

Integer Representations

Primes

Greatest Common Divisor (GCD) & Least Common Multiple (LCM)

Linear Congruences

38/71
Primes

Definition 13
An integer p > 1 is called a prime iff p has exactly two positive factors, namely 1
and p.
An integer n > 1 that is not a prime is called a composite. So, n is a composite
iff there exists an integer a with 1 < a < n such that a | n.

• The integer 1 is not a prime since it only has one positive factor.

39/71
Fundamental theorem of arithmetics
Why are primes important?

40/71
Fundamental theorem of arithmetics
Why are primes important?
Theorem 14 (Fundamental theorem of arithmetics)
Every integer n > 1 can be written uniquely as:
• a (single) prime; or
• a product of two or more primes (with duplicates allowed) such that those
prime factors are written in an increasing order.

The above theorem yields prime factorization of integers:


• 200 =
• 641 =
• 741 =
• 899 =
• 1024 =
40/71
Determining if n is prime
Trial division

Theorem 15

If n is a composite, then n has a prime factor that is less than or equal to n.

Proof?

41/71
Determining if n is prime
Trial division

Theorem 15

If n is a composite, then n has a prime factor that is less than or equal to n.

Proof?
• To determine if n is prime, it suffices to divide n with all primes less than or

equal to n.
• If any of those primes divides n, then n is composite. Otherwise, n is prime.
• Example: Is 101 prime?

41/71
Sieve of Eratosthenes
Finding all primes that are less than or equal to a given positive integer n.
• List all integers from 2 to n.
• Cross out all multiples of 2 that is greater than 2.
• From the remaining numbers, the smallest and not crossed out is 3. So,
cross out all multiples of 3 that is greater than 3.
• From the rest, the smallest and not crossed out is 5. So, cross out all
multiples of 5 that is greater than 5.
• From the rest, the smallest and not crossed out is 7. So, cross out all
multiples of 7 that is greater than 7.
• From the rest, the smallest and not crossed out is 11. So, cross out all
multiples of 11 that is greater than 11.
• and so forth ..
42/71
Find all primes not exceeding 100.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100

43/71
How many primes are there?

44/71
How many primes are there?
Theorem 16 (from Euclid)
There are infinitely many primes.
Proof:

44/71
Agenda

Divisibility and Modular Arithmetic

Integer Representations

Primes

Greatest Common Divisor (GCD) & Least Common Multiple (LCM)

Linear Congruences

45/71
Motivating question

Jakarta’s recent flood damaged Dobbie’s room quite significantly. Before Dobbie
can use his room again, he has to conduct some renovation work, which includes
installing new tiles to the floor.
The room’s shape is rectangular measuring 420 cm × 364 cm. Dobbie only
wants square tiles and moreover, he wants as few tiles as possible such that the
whole floor is perfectly covered only by square tiles, i.e., no non-square tile has to
be used. Fortunately, one of Dobbie’s business partners is a tile supplier that can
provide him with square tiles of any size.
What is the minimum number of tiles do Dobbie actually use?

46/71
Greatest common divisor (GCD)

Definition 17 (GCD)
Let a, b be integers, not both zero. The greatest common divisor (GCD) of a
and b, denoted gcd(a, b), is the largest integer that divides both a and b, i.e.,
the largest integer d such that d | a and d | b.

• gcd(36, 48) =
• gcd(25, 21) =

47/71
GCD and prime factorization

Is there a relation between GCD and prime factorization?

48/71
GCD and prime factorization

Is there a relation between GCD and prime factorization? Write the prime
factorization of:
• 36, 48, and gcd(36, 48)
• 25, 21, and gcd(25, 21)
• 120, 500, and gcd(120, 500).
Can you spot the pattern?

48/71
Let a, b be integers with a ≤ b. Also, let p1 , p2 , . . . , pn be primes such that for
every pi , pi | a or pi | b. Then, prime factorizations of a and b can be written:

a = pa11 pa22 · · · pann b = pb11 pb22 · · · pbnn

where a1 , . . . , an , b1 , . . . , bn are nonnegative integers. Then, the following


theorem holds.
Theorem 18 (GCD with prime factorization)
min(a1 ,b1 ) min(a2 ,b2 ) min(an ,bn )
gcd(a, b) = p1 p2 · · · pn

49/71
Relatively prime

Definition 19
Two integers a and b are called coprime or relatively prime iff gcd(a, b) = 1.
n integers a1 , a2 , . . . , an are pairwise coprime or pairwise relatively prime iff
gcd(ai , aj ) = 1 for 1 ≤ i < j ≤ n.

That is, two integers are coprime if their only common positive factor is 1.
• Are 10 and 21 relatively prime?
• Are 44, 50, and 63 pairwise relatively prime?
• Are 21, 25, and 56 pairwise relatively prime?

50/71
Least common multiple (LCM)

Definition 20
Least common multiple of a and b, denoted lcm(a, b), is the smallest positive
integer that is divisible by both a and b.

What is lcm(95256, 432)?

51/71
LCM and prime factorization

Can you express LCM using prime factorization?

52/71
LCM and prime factorization

Can you express LCM using prime factorization?


Write the prime factorization of 95256, 432, and their LCM. Guess the pattern.

52/71
Theorem 21
If a, b are integers with prime factorizations according to Theorem 18, then
max(a1 ,b1 ) max(a2 ,b2 )
lcm(a, b) = p1 p2 · · · pmax(a
n
n ,bn )

53/71
Relationship between GCD and LCM
Is there a relation between GCD and LCM of two integers?

54/71
Relationship between GCD and LCM
Is there a relation between GCD and LCM of two integers?
Guess the relation by first calculating the following integers:
• 36, 48, gcd(36, 48), lcm(36, 48)
• 25, 21, gcd(25, 21), lcm(25, 21)
• 120, 500, gcd(120, 500), lcm(125, 500)

54/71
Theorem 22
Let a, b be positive integers. Then, ab = gcd(a, b) · lcm(a, b)

• gcd(95256, 432) =
• lcm(36, 48) =

55/71
Calculating GCD
• Based on what we’ve seen so far, how do we calculate the GCD of two
integers?

56/71
Calculating GCD
• Based on what we’ve seen so far, how do we calculate the GCD of two
integers?
• Prime factorization

56/71
Calculating GCD
• Based on what we’ve seen so far, how do we calculate the GCD of two
integers?
• Prime factorization
• Is the above approach efficient?

56/71
Calculating GCD
• Based on what we’ve seen so far, how do we calculate the GCD of two
integers?
• Prime factorization
• Is the above approach efficient?
• In current practice, no.
• In theory, No polynomial-time algorithm for prime factorization of all
integers has been found so far. Prime factorization is in class NP, but has
not been shown to be NP-complete. It is suspected that the problem is
neither in class P nor it is NP-complete.
• Note: In 1994, Peter Shor found an algorithm for prime factorization that
could be run in polynomial time on quantum computers.

56/71
Calculating GCD
• Based on what we’ve seen so far, how do we calculate the GCD of two
integers?
• Prime factorization
• Is the above approach efficient?
• In current practice, no.
• In theory, No polynomial-time algorithm for prime factorization of all
integers has been found so far. Prime factorization is in class NP, but has
not been shown to be NP-complete. It is suspected that the problem is
neither in class P nor it is NP-complete.
• Note: In 1994, Peter Shor found an algorithm for prime factorization that
could be run in polynomial time on quantum computers.
• Is there an efficient way to calculate GCD?

56/71
Calculating GCD
• Based on what we’ve seen so far, how do we calculate the GCD of two
integers?
• Prime factorization
• Is the above approach efficient?
• In current practice, no.
• In theory, No polynomial-time algorithm for prime factorization of all
integers has been found so far. Prime factorization is in class NP, but has
not been shown to be NP-complete. It is suspected that the problem is
neither in class P nor it is NP-complete.
• Note: In 1994, Peter Shor found an algorithm for prime factorization that
could be run in polynomial time on quantum computers.
• Is there an efficient way to calculate GCD?
• Yes: the Euclidean algorithm.

56/71
Euclidean algorithm: the key idea
Let’s compute gcd(21, 78). For this, consider the integers 78, 21, 15, 6, 3, 0.
• Calculate the GCD of every two consecutive integers using any means you
know. Can you spot the pattern?
• Generalize it so that we consider gcd(a, b) for any integers a, b.

57/71
Theorem 23 (Core of Euclidean algorithm)
Let a, b be integers. Then, gcd(a, b) = gcd(b, a mod b)

• gcd(21, 78) =
• gcd(25, 21) =

Proof of Theorem 23?

58/71
Algorithm 3 (Euclidean algorithm to calculate gcd(a, b))
Input: a, b positive integers
x := a
y := b
while y 6= 0:
r := x mod y
x := y
y := r
return x x is gcd(a, b)

59/71
Euclidean algorithm using tabulation

We use a table of values rj , rj+1 , qj+1 , rj+2 for j = 0, 1, . . . where


• r0 = a, r1 = b,
• rj = rj+1 qj+1 + rj+2 for j
• iteration is terminated at j = n when rj+2 = 0 and rj+1 = gcd(a, b)

60/71
Calculate gcd(662, 414) using tabulation: iterate on j = 0, 1, . . . with r0 = a,
r1 = b, rj = rj+1 qj+1 + rj+2 for j, and terminate at j = n when rj+2 = 0 dan
rj+1 = gcd(a, b)

61/71
gcd(a, b) as linear combination of a and b

• gcd(6, 14) = 2 and 2 = (−2) · 6 + 1 · 14


• gcd(25, 21) = 1 and 1 = (−5) · 25 + 6 · 21
• gcd(36, 48) = 12 and 12 = (−1) · 36 + 1 · 48
Does this hold in general? Given a and b, can we find the correct linear
combination (on the right) for gcd(a, b)?

62/71
Theorem 24 (Bezout’s Theorem)
Let a, b be integers. Then, there exists integers s and t such that
gcd(a, b) = sa + tb.

Note: s or t can be negative.


Two ways to calculate s and t above:
• Calculate the gcd using Euclidean algorithm, and then perform the reverse
calculation.
• Direct calculation using the extended Euclidean algoritm Read
Exercise 41 in Section 4.3.

63/71
Example
Express gcd(252, 198) as a linear combination of 252 and 198.

64/71
Agenda

Divisibility and Modular Arithmetic

Integer Representations

Primes

Greatest Common Divisor (GCD) & Least Common Multiple (LCM)

Linear Congruences

65/71
Linear congruence
Modular congruence can be generalized into linear congruence of the form
ax ≡ b (mod m)

• Given integers a, b, m with m positive, we wish to find an integer x such


that the linear congruence is satisfied.
• Not every linear congruence has a solution.
• If gcd(a, m) does not divide b, then the linear congruence has no solution.
• If gcd(a, m) divides b, the linear congruence has infinitely many solutions in
one or more congruence classes.
• Special case: if gcd(a, m) = 1, all solutions are in a single, unique
congruence class. The solution can be obtained via modular inverse.
• A system of (several) linear congruences can be solved using Chinese
Remainder Theorem
• Read Section 4.4 for further details.
66/71
Modular inverse

Definition 25
Let a, m be integers with m positive. The integer ā sastisfying āa ≡ 1 (mod m)
is called inverse of a modulo m.

• Modular inverse of an integer does not always exist.


• Is 5 the inverse of 3 modulo 7?
• Does 2 have an modular inverse (modulo 4)?

67/71
When is a modular inverse guaranteed to exist?

Theorem 26
If a and m are relatively prime with m > 1, then a modular inverse of a (modulo
m) always exists. Furthermore, it is unique modular m, i.e., every other inverse
of a modulo m is congruent to it.
If gcd(a, m) = 1, inverse of a modulo m can be calculated using Bezout’s
theorem.

68/71
Examples
Calculate inverse of 4 modulo 7 and of 101 modulo 4620.

69/71
Solving linear congruences with modular inverse

Let ax ≡ b (mod m) such that gcd(a, m) = 1. We solve x as follows:


• Since gcd(a, m) = 1, a has an inverse modulo m, say ā (can be computed
using Bezout’s theorem).
• Since ā is the inverse of a modulo m, āa ≡ 1 (mod m).
• Thus, āax ≡ āb (mod m), which implies the solution x ≡ āb (mod m)

70/71
Example

Solve the linear congruence 3x ≡ 4 (mod 11).

71/71

You might also like