Professional Documents
Culture Documents
Group 1
Group 1
Group 1
GCD
Every composite number, i.e. a number with more than one factor can be written
as a product of prime numbers.
In the prime factorisation method, each given number is written as the product
of prime numbers and then find the product of the smallest power of each
common prime factor.
This method is applicable only for positive numbers, i,e. Natural numbers .
Example: Find the Greatest common factor of 24, 30 and 36.
Solution: Prime factors of 24 is 23 × 3
Prime factors of 30 = 2 × 3 × 5
Prime factors of 36 = 2² x 3²
From the factorisation, we can see, only 2 x 3 are common prime factors.
Therefore, GCD (24, 30, 36) = 2 x 3 = 6
GCD - Prime Factorization
Method
SOURCE CODE
def computeGCD(x, y):
if x > y:
small = y
else:
small = x
for i in range(1, small + 1):
if((x % i == 0) and (y % i == 0)):
gcd = i OUTPUT
return gcd
a = 60
b = 48
# prints 12
print ("The gcd of 60 and 48 is : ", end="")
print (computeGCD(60,48))
GCD - Euclidean Algorithm
Method
In this method, the largest number among the given set of numbers should be
divided by the second largest number, and again the second-largest number
should be divided by the remainder of the previous operation, this process will
continue till the remainder is zero. The divisor, when the remainder is zero, is
called the greatest common divisor of the given numbers.
Example : Find the greatest common divisor of 128 and
96.
Solution : By the method of Euclidean algorithm,
Step 1 : 128 = 96 x 1 + 32
Step 2 : 96 = 32 x 3 + 0
SOURCE CODE
# euclid algorithm for calculation of greatest common divisor
def gcd(a, b):
if a == 0 : OUTPUT
return b
return gcd(b%a, a)
a = 11
b = 15
print("gcd of ", a , "&" , b, " is = ", gcd(a, b))
The Fundamental Theorem of
Arithmetic
Examples:
. 100 = 2 . 2 . 5 . 5 = 22 . 52
. 641 = 641
. 999 = 3 . 3 . 3 . 37 = 33 . 37
. 1024 = 2 . 2 . 2 . 2 . 2 . 2 . 2 . 2 . 2 . 2 = 210
Fermat’s method of factorization
Linear congruences
Let a,b be two integers and m is the +ve integer then if a-b divides m then we say,
the relation is a congruent.
It is denoted by a ≡ b(modm)
Basic properties of Congruence
The Congruent relation is said to be equivalent relation if a,b,c belongs to (integer) Then the
relation is Conguient. if it satisfies
The following properties...
→ Reflexive property
a ≡ a (mod m)
→ Symmetric property
a ≡ b (mod m)
b ≡ a (mod m)
→ Transitive property
a ≡ b (mod in)
b ≡ c (mod m)
a ≡ c (mod m)
Linear congruences
Statement:
Let m1,m2. ...,mr, be pairwise relatively prime
positive integers
and a1, a2 ..., an arbitrary integers. Then the
system
x= a1 (mod m,)
x= a2 (mod m2)
.
.
x = an (mod mr)
has a unique solution modulo m = m1, m2...mr.
Algorithm for
Chinese Remainder Theorem