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
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...
Top Blackrock Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Blackrock Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app