0% found this document useful (0 votes)
62 views42 pages

DS Number Theory

Uploaded by

Sailesh Sailesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views42 pages

DS Number Theory

Uploaded by

Sailesh Sailesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Course Title:

Discrete Structures
Compiled by Ujjwal Rijal
[email protected]

Compiled by Ujjwal Rijal || [email protected] 1


Unit-2
Integers and Matrices
Compiled by Ujjwal Rijal
[email protected]

Compiled by Ujjwal Rijal || [email protected] 2


Integers and Division
Introduction
o The branch of mathematics which study about the integers and their properties is called
number theory.
o Computer science uses the different concept related to number theory. Here, we will
discuss the basic concept of number theory, properties of integers, divisibility, and
modular arithmetic.
Divisibility
o If a and b are integers, where a! = 0, we say a divides b if there is an integer c such that b
= ac. When a divides b then we say that a is a factor of b and b is a multiple of a. The
notational representation a | b is for a divides b.
Example-1: 4 | 12 means 4 divides 12 where a = 4, b = 12 and c = 3.
Example-2: Determine whether 5 | 7 and whether 4 | 16.
Here, 5 ∤ 7 since 7 / 5 is not an integer. On the other hand, 4 | 16 because 16 / 4 is an
integer. Compiled by Ujjwal Rijal || [email protected] 3
Division Algorithm
o Let a be an integer and d be a positive integer. Then, there are unique integers q and r, with 0 < r < d, such that a = dq + r.
Here, a is called dividend, d is called divisor, q is called quotient, and r is called remainder.
For e.g. 305 (dividend) = 10 (divisor) * 30 (quotient) + 5 (remainder).
Theorem:
Let a, b, and c be the integers. Then,
i. If a | b and a | c , then a | (b + c).
ii. If a | b , then a | bc for all integers c.
iii. If a | b and b | c , then a | c.
Proof:
i. Given that a | b and a | c , so by the definition of divisibility, we can say that there are integers p and q such that b = ap and
c = aq. From this, we can write, b + c = ap + aq i.e. b + c = a(p + q). So, from this, we can say that a divides b + c.
ii. Given that a | b , by the definition of divisibility, we can say that there is an integer p such that b = ap. So, for any integer,
we can write, bc = apc ; this means a divides bc , since pc is an integer too.
iii. Given that a | b and b | c , by the definition of divisibility, we have integers p and q such that b = ap and c = bq i.e. c =
apq. Since, pq is an integer, we can conclude that a divides c.

Compiled by Ujjwal Rijal || [email protected] 4


Modular Arithmetic – Arithmetic Modulo m
o This is an arithmetic calculation system which works only with integer number.
o When an integer a is divided by another positive integer m , then the remainder r is
obtained, such that a = m* quotient + r.
o The operation which gives remainder is known as modular operation and the process is
called modular arithmetic.
 Definition
If a and b are integers and m is a positive integer, then a is congruent to b modulo m if m
divides a – b. we use the notation a ≡ b(mod m) to indicate that a is congruent to b modulo m.
For e.g.: 23 is congruent to 11 modulo 2 , since 23 – 11 = 12 is divisible by 2.
Example: Determine whether 19 is congruent to 1 modulo 3.
Solution:
Here, a = 19 , b =1 , and m = 3.
Then, we have that: 3 divides 19 – 1 = 18 ⇒ 3 divides 18 is true.
Compiled by Ujjwal Rijal || [email protected] 5
Applications of Modular Arithmetic
 Hashing Function
o Hashing is the mapping of key or information into a fixed message.
o Suppose, a bank has records for each of its customers. Now, to access these records quickly, the account number of customers can be used as key
information, and using hashing function, we can map key into particular memory location where records are kept.
o There are different hash functions, but most commonly used one is:
h(k) = k mod m
Where,
k is the key value.
m is the size of hash table.
and, h(k) is the memory location for the records that has k as its key.
Example:
Which memory locations are assigned by the hash function h(k) = k mod 100, the rewards of bank customers with the following A/C numbers?
a. 104578690 b. 432222187
Solution:
Here, for A/C number 104578690 ; k = 104578690 , and m = 100
Then,
h(k) = k mod m
h(104578690) = 104578690 mod 100
= 90 ⇒ hash value or memory location and the record of customer with A/C number 104578690 is assigned to the memory location 90.
╬ Solve yourself for the A/C number 432222187. Compiled by Ujjwal Rijal || [email protected] 6
Applications of Modular Arithmetic
 Pseudo Random Number
o Those numbers that are generated by a process or algorithm or machine whose outcome is unpredictable, are called random numbers.
o Pseudo means false (not true), so pseudo random numbers means numbers that are generated using computer or machine.
o The most commonly used method or procedure to generate pseudo random numbers is linear congruential method.
o The linear congruential method produces sequence of integers between zero and m – 1 using the recursive formula:
xi+1 = (axi + c) mod m
where,
x0 is the initial value.
a & c are the constants.
m is the modulus.
Example: Generate first five random numbers using LCM method with x0 = 27, a = 17, c = 43 and m = 100.
Solution:
Here, x0 = 27
So, x1 = (a * x0 + c) mod 100
= (17 * 27 + 43) mod 100
= 502 mod 100
=2
Compiled by Ujjwal Rijal || [email protected] 7
Similarly,
x2 = (a * x1 + c) mod 100
= (17 * 2 + 43) mod 100
= 77 mod 100
= 77
Also,
x3 = (a * x2 + c) mod 100
= (17 * 77 + 43) mod 100
= 1352 mod 100
= 52
And,
x4 = (a * x3 + c) mod 100
= (17 * 52 + 43) mod 100
= 927 mod 100
= 27
Therefore, the sequence of random numbers is 27, 2, 77, 52, 27, ………

Compiled by Ujjwal Rijal || [email protected] 8


Primes
o A positive integer greater than 1 and divisible by only 1 or itself is called prime. If the positive integer is not a prime, then
it is a composite number. For e.g. 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 and 37.
 Theorem (The Fundamental Theorem of Arithmetic)
Statement: Every positive integer greater than one can be written uniquely as a prime or as the product of two or more
primes where the prime factors are written in order of non-decreasing size.
Example-1: Find the prime factorization of 99, 110, 645 and 875.
Solution:
The prime factorization of 99, 110, 645 and 875 are given by;
99 = 3 . 3 . 11 = 32 . 11
110 = 2 . 5 . 11
645 = 3 . 5 . 43
875 = 5 . 5 . 5 . 7 = 53 . 7

Compiled by Ujjwal Rijal || [email protected] 9


Example-2: Find the prime factorization of 7007.
Solution:
o To find the prime factorization of 7007, first perform divisions of 7007 by successive primes beginning with 2. Since, none of the primes 2, 3, 5
divides 7007. However, 7 divides, so we do 7007 / 7 = 1001.
o Next, divide 1001 by successive primes, beginning with 7. So, 1001 / 7 = 143. Continue by dividing 143 beginning with 7.
o Although 7 does not divide 143, so we try through 11, and 11 divides 143 i.e. 143 / 11 = 13, which is prime itself.
o Therefore, prime factorization of 7007 is 7 . 7 . 11 . 13 = 72 . 11 . 13.

Greatest Common Divisor (GCD) and Least Common Multiple (LCM)


 Let a and b be the integers, not both zero. The largest integer d such that d | a and d | b is called GCD of a and b. We denote gcd of a and b by
gcd(a, b).
 The least common multiple (LCM) of the positive integers a and b is the smallest positive integer that is divisible by both a and b. It is denoted
by lcm(a, b).

Relatively Prime
Two integers a and b are set to be relatively prime if gcd(a, b) = 1. For e.g. gcd(3, 5) = 1 , so 3 and 5 are relatively prime.

Compiled by Ujjwal Rijal || [email protected] 10


General approach of calculating GCD
By the general definition of gcd, we have,
For gcd(a, b), with a ≤ b.
if a = 0, then return b.
else,
gcd(a, b) = (b mod a, a)
Example-1: Find the GCD of 13 and 34. Example-2: Find the GCD of 64 and 112.
Solution: Solution:
We have, gcd(13, 34) = (34 mod 13, 13) We have, gcd(64, 112) = (112 mod 64, 64)
= (8, 13) = (48, 64)
= (13 mod 8, 8) = (64 mod 48, 48)
= (5, 8)= (16, 48)
= (8 mod 5, 5) = (48 mod 16, 16)
= (3, 5) = (0, 16)
= (5 mod 3, 3) Here, a = 0, so by the condition, return b = 16 as the gcd of 64 and 112.
= (2, 3) ∴ GCD(64, 112) = 16.
= (3 mod 2, 2) Example-3: Find the GCD of 256 and 1792.
= (1, 2) Solution:
= (2 mod 1, 1) We have, gcd(256, 1792) = (1792 mod 256, 256)
= (0, 1) = (0, 256)
Here, a = 0, so by the condition, return b = 1 as the gcd of 13 and 34. Here, a = 0, so by the condition, return b = 256 as the gcd of 256 and 1792.
Compiled by Ujjwal Rijal || [email protected] 11
∴ GCD(13, 34) = 1. ∴ GCD(64, 1792) = 256.
Pairwise Relatively Prime
 The integers a1 , a2 , a3 , ……, an are pairwise relatively prime if gcd(ai , aj) = 1, where 1 ≤ i ≤ j ≤ n.
Example: Determine whether the integers 10, 17 and 21 are pairwise relatively prime.
Solution:
Here, we know that;
gcd(10, 17) = 1
gcd(10, 21) = 1
gcd(17, 21) = 1
Therefore, the given number sequence 10, 17 and 21 are pairwise relatively prime.

Using Prime Factorization Method to calculate GCD and LCM


o Suppose, let a and b are two integers, which are not equal to zero i.e. a, b ≠ 0.
o Now, let P1 , P2 , ……….. , Pn be the prime factors of either a or b.
o The prime factors of a =, ……….. ,
o And, the prime factors of b =, ……….. ,

GCD(a, b) = ** ……… *
Then, we have,

and, LCM(a, b) = ** ……… *


Compiled by Ujjwal Rijal || [email protected] 12
Using Prime Factorization Method to calculate GCD and LCM
Example-1: Use prime factorization method to find the gcd of 12 and 30.
Solution:
Prime factorization of 12 and 30 is achieved as follows:
12 = 2 . 2 . 3 30 = 2 . 3 . 5
= 22 . 31 . 50 = 2 1 . 31 . 51
Now, by the rule, we have,
gcd(a, b) = ** ……… *
Therefore, gcd(12, 30) = . .
= 21 . 31 . 50
=6
∴ gcd(12, 30) = 6 , through the prime factorization method.

Compiled by Ujjwal Rijal || [email protected] 13


Using Prime Factorization Method to calculate GCD and LCM
Example-2: Use prime factorization method to find the LCM of 12 and 18.
Solution:
Prime factorization of 12 and 18 is achieved as follows:
12 = 2 . 2 . 3 18 = 2 . 3 . 3
= 22 . 31 = 2 1 . 32
Now, by the rule, we have,
LCM(a, b) = ** ……… *
Therefore, LCM(12, 18) = .
= 22 . 32
= 36
∴ LCM(12, 18) = 36 , through the prime factorization method.

Compiled by Ujjwal Rijal || [email protected] 14


Theorem-1
 If a and b are two positive integers, then GCD(a, b) . LCM(a, b) = ab.
Proof:
Let, P1 , P2 , ……. , Pn be the prime factors of either a or b.
Then, we get,
a =, ……….. , ; and b =, ……….. ,
Here, some of ai and bi may be zero, with ai be the minimum value , and bi be the maximum value.
So, it follows that: GCD(a, b) = ** ……… *
And, LCM(a, b) = ** ……… *
Now, we have,
GCD(a, b) . LCM(a, b) = . . ……….. .
= . . …. ) . . . …. )
=a.b
∴ GCD(a, b) . LCM(a, b) = ab.
This completes the proof.
Hence, proved.
Compiled by Ujjwal Rijal || [email protected] 15
Theorem-2
 If d is GCD(a, b) i.e. d = GCD(a, b), then
(i) d = sa + tb for some integers s and t. (These are not necessarily positive).
(ii) If c is any other common divisor of a and b, then c | d.
The Euclidean Algorithm
It is used to compute greatest common divisor (GCD). The GCD, represented as gcd(a, b) is defined as:
gcd(a, b) = d, where d is the largest number that divides both a and b.
If gcd(a, b) = 1, then we say that a and b are relatively prime, which means that both a and b do not divide each other.
Pseudo code for Euclidean algorithm
INPUT: Two non-negative integers a and b with b ≤ a. (Here, you can use a and b interchangeably).
OUTPUT: gcd(a, b)
1. While b > 0, do
set r = a mod b,
a = b,
b = r.
2. Else, return a.
Compiled by Ujjwal Rijal || [email protected] 16
The Euclidean Algorithm
Suppose that a > b > 0 (Otherwise interchange a and b). Then, by the Division Algorithm i.e. a = dq + r, we can write:
a = k1 b + r 1 , where k1 is Z+ and 0 ≤ r1 < b.

NOTE: In final computation, take either the last of the non-zero divisors or take last non-zero remainder to get the final
result of the gcd of the given two numbers.

Example-1: Find the GCD of 34 and 190 using the Euclidean algorithm.
Solution:
Here, we need to find GCD(190, 34) , with consideration of a > b.
Now, using the Euclidean algorithm to compute GCD(190, 34) through a = k 1b + r1 as follows:
190 = 34 * 5 + 20 (Hints: For ease, always take larger number on left)
34 = 20 * 1 + 14
20 = 14 * 1 + 6
14 = 6 * 2 + 2
6=2*3+0
So, GCD(190, 34) = 2 , the last non-zero remainder or last of the non-zero divisors.
Compiled by Ujjwal Rijal || [email protected] 17
Example-2: Find the GCD of 111 and 421 using the Euclidean algorithm.
Solution:
Here, we need to find GCD(421, 111) , with consideration of a > b.
Now, using the Euclidean algorithm to compute GCD(421, 111) through a = k 1b + r1 as follows:
421 = 111 * 3 + 88 (Hints: For ease, always take larger number on left)
111 = 88 * 1 + 23
88 = 23 * 3 + 19
23 = 19 * 1 + 4
19 = 4 * 4 + 3
4=3*1+1
3=1*3+0
So, GCD(421, 111) = 1 , the last non-zero remainder or last of the non-zero divisors.
Example-3: Find the GCD of 172 and 786 using the Euclidean algorithm.
(Test yourself )

Compiled by Ujjwal Rijal || [email protected] 18


The Extended Euclidean Algorithm
 It is just another way of finding GCD, as we did it using Euclidean algorithm.
 The Extended Euclidean algorithm is an extension to the Euclidean algorithm, and computes, in addition to
the GCD of integers a and b, also the coefficients of Bezout’s identity, which are the integers s and t , such
that:
d = sa + tb , where s and t are the Bezout’s identity, and d is gcd(a, b).
Bezout’s Identity
 Bezout’s Identity, also called Bezout’s Lemma is the following theorem:
Let a and b be the integers with greatest common divisor d. Then, there exist integers s and t such that sa + tb =
d. More generally, the integers of the form sa + tb are exactly the multiples of d.
 In short, the Extended Euclidean Algorithm stands as:
 If d is GCD(a, b) i.e. d = GCD(a, b), then
d = sa + tb for some integers s and t. (These are not necessarily positive).
 It means that Extended Euclidean algorithm is used for finding the GCD of two positive integers a and b and
writing this GCD as an integer linear combination of a and b for some integers s and t , which are not
necessarily positive.
 Note: Extended Euclidean algorithm does not care about the quotient, but cares only about the remainders.
Compiled by Ujjwal Rijal || [email protected] 19
Example-1: Find the GCD of 34 and 190 and represent these integers in the linear combination using the Extended
Euclidean algorithm
Solution:
Here, we need to find GCD(190, 34) , with consideration of a > b.
Now, using the Euclidean algorithm to compute GCD(190, 34) through a = k 1b + r1 as follows:
190 = 34 * 5 + 20 (Hints: For ease, always take larger number on left)
34 = 20 * 1 + 14
20 = 14 * 1 + 6
14 = 6 * 2 + 2
6=2*3+0
So, GCD(190, 34) = 2 , the last non-zero remainder or last of the non-zero divisors.
Here, we have, a = 190 , b = 34 , and d = GCD(a, b).
i.e. d = GCD(190, 34) = 2.
Now, let s and t be the two integers, which are not necessarily positive. Thus, the integers a and b can represented in a linear
combination as follows:
d = sa + tb (By the Extended Euclidean Algorithm).
i.e. 2 = 190s + 34t.
This is the required linear combination of 190 Compiled
and 34byfor some
Ujjwal integers
Rijal || s and t. Now, computing the values of s and t 20as:
[email protected]
Then, we have,
d = GCD(190, 34) = 2
= 14 – 2( 6)
= 14 – 2 [20 – 1(14)]
= 14 – 2(20) + 2(14)
= 3(14) – 2(20)
= 3[34 – 1(20)] – 2(20)
= 3(34) – 3(20) – 2(20)
= 3(34) – 5(20)
= 3(34) – 5[190 – 5(34)]
= 3(34) – 5(190) + 25(34)
= 28(34) – 5(190)
i.e. –5(190) + 28(34).
Now, comparing this with sa + tb, we get,
a = 190, b = 34, s = -5 , and t = 28.
Thus, the required values of s and t are -5 and 28 respectively.
Compiled by Ujjwal Rijal || [email protected] 21
Example-2: Let a = 108 and b = 60. Then, compute the values of some integers s and t for d = sa + tb using the
Extended Euclidean Algorithm, where d is the greatest common divisor of 108 and 60.
Solution:
Here, we need to find GCD(108, 60) , with consideration of a > b.
Now, using the Euclidean algorithm to compute GCD(108, 60) through a = k 1b + r1 as follows:
108 = 60 * 1 + 48 (Hints: For ease, always take larger number on left)
60 = 48 * 1 + 12
48 = 12 * 4 + 0
So, GCD(108, 60) = 12 , the last non-zero remainder or last of the non-zero divisors.
Here, we have, a = 108 , b = 60 , and d = GCD(a, b).
i.e. d = GCD(108, 60) = 12.
Now, let s and t be the two integers, which are not necessarily positive. Thus, the integers a and b can represented in a linear
combination as follows:
d = sa + tb (By the Extended Euclidean Algorithm).
i.e. 12 = 108s + 60t.
This is the required linear combination of 108 and 60 for some integers s and t. Now, computing the values of s and t as:

Compiled by Ujjwal Rijal || [email protected] 22


Then, we have,
d = GCD(108, 60) = 12
= 60 – 1(48)
= 60 – 1 [108 – 1(60)]
= 60 – 1(108) + 1(60)
= 2(60) – 1(108)
i.e. – 1(108) + 2(60)
Now, comparing this with sa + tb, we get,
a = 108, b = 60, s = -1 , and t = 2.
Thus, the required values of s and t are -1 and 2 respectively.

Example-3: Let a = 2078 and b = 2021. Then, compute the values of some integers s and t for d = sa + tb using the
Extended Euclidean Algorithm, where d is the greatest common divisor of 2078 and 2021.

Example-4: Express the gcd of 124 and 232 as the linear combination of these integers. Here, consider the condition as
gcd(a, b) = gcd(124, 232).
(Hints for example-4: d = 124s + 232t) (Test Yourself)
23
Compiled by Ujjwal Rijal || [email protected]
Pseudo Code for The Extended Euclidean Algorithm
INPUT: Two non-negative integers a and b with a ≥ b.
OUTPUT: d = gcd(a, b) and integers x and y satisfying ax + by = d.
1. If b = 0 , then set d = a, x = 1, y = 0 ,and return (d, x, y).
2. Set x2 = 1, x1 = 0, y2 = 0, y1 = 1.
3. While b > 0 , do
i. q = floor(a/b), r = a – qb, x = x2 – qx1 , y = y2 – qy1.
ii. a = b, b = r, x2 = x1 , x1 = x , y2 = y1 , y1 = y.
4. Set d = a, x = x2 , y = y2 , and return (d, x, y).

Compiled by Ujjwal Rijal || [email protected] 24


Integers and Algorithms
 Integer Representations – (Binary, Octal, Hexadecimal and conversions) ------ (Test Yourself)  
Integer Addition Algorithm
procedure add(a, b: positive integers)
{the binary expansion of a and b are (an-1 an-2 …… a1 a0)2 and (bn-1 bn-2 …… b1 b0)2 , respectively}.
c=0
for j = 0 to n –1
begin
d = ∟(aj + bj + c) / 2⅃
sj = aj + bj + c – 2d
c=d
end
sn = c
{the binary expansion of the sum is (s 0 sn-1 by
Compiled …… Ujjwal s 0)2||
Rijal }[email protected] 25
Integer Multiplication Algorithm
procedure multiply(a, b: positive integers)
{the binary expansion of a and b are (an-1 an-2 …… a1 a0)2 and (bn-1 bn-2 …… b1 b0)2 , respectively}
c=0
for j = 0 to n –1
begin
if bj = 1 then cj = -a ; shifted j-places.
else cj = 0
and
{c0 c1 ………., cn-1 are the partial products}
P=0
for j = 0 to n – 1
P = P + cj
end
{P is the value of ab}
Modular Exponential Algorithm
(Already discussed in the previous section)
Compiled by Ujjwal Rijal || [email protected] 26
Integer Division Algorithm
procedure division(a: integer, d: positive integer)
a=0
r=|a|
While r ≥ d
begin
r=r–d
q=q+1
end
if a < 0 and r > 0 then
begin
r=d–r
q = – (q + 1)
end
{q is the quotient and rCompiled
is thebyremainder}
Ujjwal Rijal || [email protected] 27
Modular Multiplicative Inverse (MI)
 A modular multiplicative inverse of an integer a is an integer x such that the product ax is congruent to 1
with respect to the modulus m.
 In standard notation of modular arithmetic, it can be written as:
ax ≡ 1(mod m)
 The value of x should be in {1, 2, 3, …….., m-1} i.e. in the range of integer modulo m.
 The multiplicative inverse (MI) of “a modulo m” exists if and only if a and m are relatively prime.
.i.e. GCD(a, m) = 1.
Example-1: Find the multiplicative inverse of 5 with the condition of 5 -1 (mod 12).
OR Find the multiplicative inverse of 5 in Z12 .
Solution:
Here, by the standard notation of MI, we have,
ax ≡ 1(mod m)
By comparison, in this situation, we get,
a = 5 and m = 12 i.e. 5x ≡ 1(mod 12) and here, x is the multiplicative inverse of 5.
Now, to determine the multiplicative inverse of 5, we first find out the GCD of 5 and 12 i.e. a and m, to check if it exists.
For this, we use Euclidean Algorithm as follows:Compiled by Ujjwal Rijal || [email protected] 28
GCD(5, 12) is given by,
12 = (5) . 2 + 2
5 = (2) . 2 + 1
2 = (1) . 2 + 0
Thus, GCD(5, 12) = 1. It means that the multiplicative inverse of 5 exists, since 5 and 12 are relatively prime.
Further, to compute the value of x i.e. multiplicative inverse of 5, we use Extended Euclidean Algorithm as follows:
Why because, as per the condition, 12 is the
GCD(5, 12) = 1
modulus. So, anything times modulus is 0. S0, 2 (12)
1 = 5 – 2(2) = 0.
1 = 1(5) – 2 [12 – 2(5)] We have, 5(5) – 2(12) = 1
It means that,
1 = 1(5) – 2(12) + 4(5)
5(5) – 0 =1 5(5) = 1
1 = 5(5) – 2(12) i.e. 5 = 1 / 5 5-1 (Multiplicative inverse of 5).
Hence, 5 is the multiplicative inverse of 5.
Example-2: Find the multiplicative inverse of 27 with the condition of 27 -1 (mod 392).
Solution:
Here, by the standard notation of MI, we have,
ax ≡ 1(mod m)
By comparison, in this situation, we get,
Compiled by Ujjwal Rijal || [email protected] 29
a = 27 and m = 392 i.e. 27x ≡ 1(mod 392) and here, x is the multiplicative inverse of 27.
Now, to determine the multiplicative inverse of 27, we first find out the GCD of 27 and 392 i.e. a and m, to check if it exists.
For this, we use Euclidean Algorithm as follows:
GCD(27, 392) is given by,
392 = (27) . 14 + 14
27 = (14) . 1 + 13
14 = (13) . 1 + 1
13 = (1) . 13 + 0
Thus, GCD(27, 392) = 1. It means that the multiplicative inverse of 27 exists, since 27 and 392 are relatively prime.
Further, to compute the value of x i.e. multiplicative inverse of 27, we use Extended Euclidean Algorithm as follows:
GCD(27, 392) = 1
1 = 14 – 1(13)
1 = 1(14) – 1 [27 – 1(14)]
1 = 1(14) – 1(27) + 1(14)
1 = 2(14) – 1(27)
1 = 2[392 – 14(27)] – 1(27)
1 = 2(392) – 28(27) – 1(27)
1 = 2(392) – 29(27)
Since we can replace -29 with 363 onwards as, 2(392) + 363(27) = 1
Here, MI of 27 is obtained as negative integer, so subtract this from modulus
i.e. 0 +to363(27)
get the=final
1 [∵MI of 27.= 0, as 392 is the modulus]
2(392)
i.e. 392 – 29 = 363. i.e. 363(27) = 1
Compiled by Ujjwal Rijal || [email protected] So, 363 = 1 / 27 = 27-1 (Multiplicative inverse of 27). 30
Hence, 363 is the multiplicative inverse of 27.
Applications of Number Theory
Linear Congruencies
o A congruence of the form ax ≡ b(mod m) , where x is an unknown integer is called a linear congruence in one variable.
o Linear congruence method is used to find the value of that unknown integer x.
o It is important to know that if x0 is a solution for a linear congruence, then all integers xk such that xk ≡ x0(mod m) are the
solutions of the linear congruence.
o Notice also that ax ≡ b(mod m) is equivalent to a linear Diophantine equation i.e. there exists y such that ax – my = b.
o In short, a linear congruence is a problem of finding an unknown integer x that satisfies the equation ax ≡ b(mod m). The
general solutions for x are the incongruent solutions.
 Rules for finding x in Linear Congruencies
i. Find GCD(a, m) = d (let).
ii. Proceed b / d → if possible → Then, it confirms that the solution of x exists.
iii. Find d(mod m) → These are the possible number of possible solutions of x.
iv. Divide both the sides by d.
v. Multiply both the sides by the multiplicative inverse (MI) of a.
i.e. (a.a-1) x ≡ b. a-1(mod m).
vi. General solution equation is given by:
xk = x0 + k () , where k = 0, Compiled by Ujjwal Rijal || [email protected]
1, 2, ……….. , (d – 1). 31
Example-1: Find the solution of x in 14x ≡ 12(mod 18) , the Linear Congruencies.
OR Solve the given linear congruency: 14x ≡ 12(mod 18).
Solution:
Here, by the standard notation of Linear Congruencies, we have,
ax ≡ b(mod m)
By comparison, in this situation, we get,
a = 14 , b = 12 and m = 18.
Now, we have the following procedures to find the solution for x; an unknown integer:
i. GCD(a, m) = GCD(14, 18) = 2 = d (let) → By the Euclidean Algorithm.
ii. b / d = 12 / 2 = 6. → It implies that the solution of x exists.
iii. Now, the number of possible solutions of x is determined as:
d(mod m) = 2(mod 18) = 2.
Thus, two possible solutions of x exist.
iv. Now, dividing both sides by d as:
≡ ( mod )
i.e. 7x ≡ 6(mod 9)
v. Now, multiplying both the sides by the multiplicative inverse of a in (iv) as:
(7. 7-1) x ≡ 6. 7-1 (mod 9)
Compiled by Ujjwal Rijal || [email protected] 32
i.e. x ≡ 6. 7-1 (mod 9)
Now, computing the multiplicative inverse of 7 in 7 -1 (mod 9); which is equals to 4.
i.e. The multiplicative inverse of 7 is 4 and we replace 7 -1 by 4.
So, x ≡ 6. 7-1 (mod 9) becomes as follows:
x ≡ 6. 4 (mod 9)
x ≡ 24 (mod 9)
Thus, x0 = 6(mod 18) ; which is the initial value.
vi. Since, we have two possible values, so using general formula, we compute next value as follows:
xk = x0 + k () , where k = 0, 1, 2, ……….. , (d – 1).
So, x1 = 6 + 1 . ()
=6+9
Thus, x1 = 15(mod 18).
Hence, the two possible incongruent solutions of x are 6(mod 18) and 15(mod 18).
Example-2: Find the solution of x in 3x ≡ 12(mod 6) , the Linear Congruencies.
Example-3: Find the solution of x in 9x ≡ 15(mod 24) , the Linear Congruencies.
Example-4: Find the solution of x in 18x ≡ 144(mod 99) , the Linear Congruencies.
(Test Yourself)
Compiled by Ujjwal Rijal || [email protected] 33
Applications of Number Theory
Chinese Remainder Theorem (CRT)
o Chinese Remainder Theorem, an ancient theorem that gives the conditions necessary for multiple equations to
have a simultaneous integer solution.
o The theorem has its origin in the work of 3rd-century-AD by the Chinese mathematician Sun Zi, although the
complete theorem was first given in 1247 by Qin Jiushao.
o CRT is used to solve a system of simultaneous linear congruencies.
o Chinese Remainder Theorem (CRT) states that:
If m1 , m2 , …… , mk are pairwise relatively prime positive integers, and if a1 , a2 , …….. , ak are any integers,
then the simultaneous congruencies x ≡ a1 (mod m1) , x ≡ a2 (mod m2) , ………. , x ≡ ak (mod mk) have a
solution, and the solution is unique (or common) modulo m, where m = m1m2 ………mk .
o It means that the General form of CRT is as follows:
x ≡ a1 (mod m1)
x ≡ a2 (mod m2)

x ≡ ak (mod mk).
Compiled by Ujjwal Rijal || [email protected] 34
o The solution of x exists if and only if m1 , m2 , ….., mk are pairwise relatively prime to each other.
Rules for finding x by using Chinese Remainder Theorem (CRT)
i. Determine whether the solution of x exists or not i.e. solution exists if and only if m1 , m2 , ….., mk are
pairwise relatively prime to each other.
ii. Find out common modulus m as:
m = m1 * m2 * ….. * mk .
iii. Find individual m’s by computing as:
z1 = m / m1 , z2 = m / m2 , ……… , zk = m / mk
iv. Find out inverse of z1 , z2 , …… zk with respect to m1 , m2 , …….. , mk respectively.
i.e. z1-1 = z1 (mod m1) , z2-1 = z2 (mod m2) , ……….. , zk-1 = zk (mod mk) , respectively.
v. Finally, we compute the value of x as:
x = a1w1 + a2w2 + ………….. + akwk (mod m)

Where, w1 = z1 * z1-1 , w2 = z2 * z2-1 , …………, wk = zk * zk-1 , respectively.

Compiled by Ujjwal Rijal || [email protected] 35


Example-1: Solve the given simultaneous linear congruencies:
x ≡ 4(mod 11)
x ≡ 5(mod 7)
x ≡ 6(mod 13)
Solution:
Here, our target is to find out one value of x which satisfies all the three given linear congruencies.
Now, for this, we proceed as follows:
Now, by comparison, we have,
a1 = 4 , a2 = 5 , a3 = 6 , m1 = 11 , m2 = 7 , m3 = 13.
So, we have,
i. Check if solution of x exists:
gcd(m1 , m2) = gcd(11, 7) = 1
gcd(m1 , m3) = gcd(11, 13) = 1
gcd(m2 , m3) = gcd(7, 13) = 1
So, solution of x exists, since m1 , m2 , and m3 are pairwise relatively prime.
ii. Find common modulus m as:
m = m1 * m2 * m3 = 11 . 7 . 13 = 1001.Compiled by Ujjwal Rijal || [email protected] 36
iii. Now, we have,
z1 = m / m1 = 1001 / 11 = 91.
z2 = m / m2 = 1001 / 7 = 143.
z3 = m / m3 = 1001 / 13 = 77.
iv. Now, compute the inverse of z1 , z2 , and z3 with respect to m1 , m2 , and m3 respectively.
i.e. z1-1 = 91-1 (mod 11) = 4.
z2-1 = 143-1 (mod 7) = 5.
z3-1 = 77-1 (mod 13) = 12.
Here, we have already completed the procedure to compute the multiplicative inverse of a number. So, test
yourself.
v. Then, compute the values of w1 , w2 , and w3 as:
i.e. w1 = z1 * z1-1 = 91 . 4 = 364.
w2 = z2 * z2-1 = 143 . 5 = 715.
w3 = z3 * z3-1 = 77 . 12 = 924.

Compiled by Ujjwal Rijal || [email protected] 37


vi. Finally, compute the value of x as:
i.e. x = a1w1 + a2w2 + ………….. + akwk (mod m).
Here, we have three linear congruencies, so we have, x = a 1w1 + a2w2 + a3w3 (mod m).
= (4 . 364) + (5 . 715) + (6 . 924) (mod 1001).
= 1456 + 3575 + 5544 (mod 1001).
= 10575 (mod 1001).
= 565.
Hence, the solution of x is 565 which satisfies the given all three linear congruencies.
Example-2: Solve the given simultaneous linear congruencies:
x ≡ 1(mod 5)
x ≡ 1(mod 7)
x ≡ 3(mod 11)
Example-3: Solve the given simultaneous linear congruencies:
x ≡ 6(mod 11)
x ≡ 13(mod 16)
x ≡ 9(mod 21)
Compiled by Ujjwal Rijal || [email protected] 38
x ≡ 19(mod 25)
Zero-One Matrix (Or Boolean Matrix)
o A Boolean matrix or (0, 1) matrix is a matrix with entries from the Boolean domain B = {0, 1}. Such a matrix can be used
to represent a binary relation between a pair of finite sets.
o In other words, A Boolean matrix is an m x n matrix whose entries are either Zero (0) or One (1).
o Algorithms operating on discrete structures represented by zero-one matrices are based on the Boolean arithmetic.
Boolean Matrix Operations
1. Boolean Join and Boolean Meet
Let, A = [aij] and B = [bij] be (m x n) Boolean matrices. We define A ∨ B , the join of A and B and A ∧ B , the meet of A and
B as follows:

2. Boolean Product

Compiled by Ujjwal Rijal || [email protected] 39


Zero-One Matrix (Or Boolean Matrix)
3. Boolean Power

Example-1: Find the Boolean join, meet and product of the given Boolean matrices A and B:
A = and B =
Solution:
Join (A ∨ B) = =
Meet (A ∧ B) = =

Compiled by Ujjwal Rijal || [email protected] 40


And, Boolean Product (A ⊙ B) = = .
Example-2: Let Boolean matrix, A = . Find An for all integers n.
Solution:
Here, we are going to compute the power of Boolean matrix A.
Now, we continuously use Boolean product of A with A to get the power of A itself.
i.e. A2 = A ⊙ A = ⊙ =
Now, A3 = A2 ⊙ A = Then, A4 = A3 ⊙ A =
And then, A5 = A4 ⊙ A =
Here, we know that, Ar is defined to be In. It means that it needs to be the identity matrix.
Thus, An = A5 for all positive integers n ≥ 5.

Compiled by Ujjwal Rijal || [email protected] 41


Example-3: Find the Boolean join, meet and product of the given Boolean matrices A and B:
A = and B =

Example-4: Find the Boolean join, meet and product of the given Boolean matrices A and B:
A = and B =

Example-5: Find the Boolean Product of A and B:


A = and B =

Compiled by Ujjwal Rijal || [email protected] 42

You might also like