Copy of Test Taking Strategies by Slidesgo
Copy of Test Taking Strategies by Slidesgo
GREATEST
COMMON
DIVISOR
Table of contents
01 Introduction
03 Practice Problems
04 Properties
#include 3.0
01
What is GCD ?
“GCD of two numbers a and b is
the largest number that divides
both a and b”
EXAMPLE
Prime factors of 24 = 2 × 2 × 2 × 3
Prime factors of 30 = 2 × 3 × 5
Common factors of 24 and 30 = 2 × 3
So , GCD of 24 and 30 = 6
CHOCOLATE QUESTION
02
Methods
ITERATIVE METHOD
● Iteration: It iterates through
numbers from 1 up to the
minimum of a and b.
● Divisibility Check: For each
number i, it checks if both a
and b are divisible by i without
remainder.
● Update GCD: If i is a common
divisor, it updates the GCD_Num
variable with the current value
of i
But what is it’s Time Complexity?
Number of
iterations
min(a,b)
Time Complexity : O(min(a,b))
Time Complexity :
O(log(min(n1,n2)))
03
Practice
Problems
Problem : Check if two numbers are co-prime
or not
Input : 2 3
Output :??
CODE
OUTPUT : Co-Prime
Another one ?
Output :??
#include 3.0
04
Properties
Properties
1. gcd (a , b) = gcd (b,a)
3. gcd(a , 0) = a
CREDITS: This presentation template was created by Slidesgo, and
includes icons by Flaticon, and infographics & images by Freepik