From f5a05b5a568750e965f2b4ae787c4b11bed84bbc Mon Sep 17 00:00:00 2001 From: BruceSiavichay Date: Sun, 8 Feb 2026 14:55:08 -0500 Subject: [PATCH] Implemented GCD function --- students_submissions/gcd_bns24.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 students_submissions/gcd_bns24.py diff --git a/students_submissions/gcd_bns24.py b/students_submissions/gcd_bns24.py new file mode 100644 index 0000000..e1c008d --- /dev/null +++ b/students_submissions/gcd_bns24.py @@ -0,0 +1,22 @@ +def gcd(a: int, b: int) -> int: + """ + Calculate the greatest common divisor (GCD) of two integers a and b + using the Euclidean algorithm. + """ + # Implement your solution here + if a == 0 and b == 0: + print("Error: Undefined.") + return None + + if b == 0: + return abs(a) #gcd is never negative + return gcd(b, a%b) + +# Test cases +print(gcd(54, 24)) # Expected output: 6 +print(gcd(48, 18)) # Expected output: 6 +print(gcd(101, 10)) # Expected output: 1 +print(gcd(0, 0)) # Expected output: "Error: Undefined." +print(gcd(-36, 6)) # Expected output: 6 +print(gcd(-36, -6)) # Expected output: 6 +print(gcd(7, 11)) # Expected output: 1