Greatest Common Divisor
Advanced
Task
Let's have some fun with numbers! Your challenge is to write a function that calculates the Greatest Common Divisor (GCD) of two positive integers. The GCD of two numbers is the largest number that divides both of them without leaving a remainder.
Example
Here's how the GCD works:
Suppose you have the numbers 8 and 12:
- The divisors of 8 are 1, 2, 4, 8
- The divisors of 12 are 1, 2, 3, 4, 6, 12
The common divisors are 1, 2, 4. Therefore, the GCD is 4.
Your task is to implement a function calculate_gcd that takes two arguments, which are the integers you want to find the GCD for, and returns the GCD.
Usage
calculate_gcd(8, 12) # Output: 4 calculate_gcd(18, 48) # Output: 6 calculate_gcd(10, 25) # Output: 5 calculate_gcd(100, 10) # Output: 10
Have fun coding, and remember to think about the Euclidean algorithm, which is a neat way of calculating the GCD efficiently!
Inputs
Arg 1:
8Arg 2:
12Expected Output
4Actual Output