DS Number Theory
DS Number Theory
Discrete Structures
Compiled by Ujjwal Rijal
[email protected]
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.
GCD(a, b) = ** ……… *
Then, we have,
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 )
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).
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)
2. Boolean Product
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) = =
Example-4: Find the Boolean join, meet and product of the given Boolean matrices A and B:
A = and B =