Greatest Common Divisor Problem Statement
You are tasked with finding the greatest common divisor (GCD) of two given numbers 'X' and 'Y'. The GCD is defined as the largest integer that divides both of the given numbers.
Example:
Input:
X = 20, Y = 15
Output:
5
Explanation:
The greatest common divisor of 20 and 15 is 5, since 5 divides both 20 and 15 without a remainder
Input:
First line contains an integer 'T', the number of test cases.
Each test case consists of two space-separated integers 'X' and 'Y'.
Output:
For each test case, output the greatest common divisor of 'X' and 'Y', each on a new line.
Constraints:
- 1 <= T <= 10
- 1 <= X, Y <= 10^9

AnswerBot
4mo
Find the greatest common divisor (GCD) of two given numbers 'X' and 'Y'.
Iterate from 1 to the minimum of X and Y, check if both X and Y are divisible by the current number, update GCD if true
Use Eucli...read more

Bhavishya Garg
1y
# Recursive function to return gcd of a and b
def
gcd(a, b):
# Everything divides 0
if
(a ==
0):
return
b
if
(b ==
0):
return
a
# base case
if
(a ==
b):
return
a
# a is greater
if
(a > b):
return
gc...read more
Help your peers!
Add answer anonymously...
Blackrock Software Developer interview questions & answers
A Software Developer was asked Q. Validate Binary Search Tree Problem Statement Your task is to determine if a giv...read more
A Software Developer was asked Q. Bridge in Graph Problem Statement Given an undirected graph with V vertices and ...read more
A Software Developer was asked Q. Shortest Distance in a Binary Search Tree Your task is to determine the shortest...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Validate Binary Search Tree Problem Statement Your task is to determine if a giv...read more
A Software Developer was asked Q2. Bridge in Graph Problem Statement Given an undirected graph with V vertices and ...read more
A Software Developer was asked Q3. Shortest Distance in a Binary Search Tree Your task is to determine the shortest...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

