0% found this document useful (0 votes)
14 views24 pages

Copy of Test Taking Strategies by Slidesgo

The document provides an overview of the Greatest Common Divisor (GCD), including its definition, methods for finding it such as the iterative method and the Euclidean algorithm, and its properties. It also includes practice problems related to GCD and co-primality. Key points include time and space complexity analyses for the methods discussed.

Uploaded by

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

Copy of Test Taking Strategies by Slidesgo

The document provides an overview of the Greatest Common Divisor (GCD), including its definition, methods for finding it such as the iterative method and the Euclidean algorithm, and its properties. It also includes practice problems related to GCD and co-primality. Key points include time and space complexity analyses for the methods discussed.

Uploaded by

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

#include 3.

GREATEST
COMMON
DIVISOR
Table of contents

01 Introduction

02 Methods of finding GCD

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

What is the range of gcd(a,b)??


#include 3.0

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))

Space Complexity : O(1)


Euclidean Algorithm

Subtract the smaller number


From the larger one until one
of the Numbers is zero or two
Numbers are equal
Euclidean Algorithm
(Modulo)
Replace the larger number with
it’s modulus with smaller
number until one of them is
zero
Has Time Complexity Reduced ??
Complexity Analysis

Time Complexity :
O(log(min(n1,n2)))

Since , each time either number is


being reduced to it’s half or less
Built in Function
#include 3.0

03

Practice
Problems
Problem : Check if two numbers are co-prime
or not

Input : 2 3

Output :??
CODE

OUTPUT : Co-Prime
Another one ?

Problem : You are given a positive integer 𝑥. Find


any such 2 positive integers 𝑎 and 𝑏 such that 𝐺𝐶𝐷
(𝑎,𝑏)+𝐿𝐶𝑀(𝑎,𝑏)=𝑥
.
Input : 14

Output :??
#include 3.0

04

Properties
Properties
1. gcd (a , b) = gcd (b,a)

2. a * b = gcd (a,b) * lcm (a,b)

3. gcd(a , 0) = a
CREDITS: This presentation template was created by Slidesgo, and
includes icons by Flaticon, and infographics & images by Freepik

You might also like