MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / greatest_common_divisor

Function greatest_common_divisor

maths/greatest_common_divisor.py:10–36  ·  view source on GitHub ↗

Calculate Greatest Common Divisor (GCD). >>> greatest_common_divisor(24, 40) 8 >>> greatest_common_divisor(1, 1) 1 >>> greatest_common_divisor(1, 800) 1 >>> greatest_common_divisor(11, 37) 1 >>> greatest_common_divisor(3, 5) 1 >>> greatest_common_divi

(a: int, b: int)

Source from the content-addressed store, hash-verified

8
9
10def greatest_common_divisor(a: int, b: int) -> int:
11 """
12 Calculate Greatest Common Divisor (GCD).
13 >>> greatest_common_divisor(24, 40)
14 8
15 >>> greatest_common_divisor(1, 1)
16 1
17 >>> greatest_common_divisor(1, 800)
18 1
19 >>> greatest_common_divisor(11, 37)
20 1
21 >>> greatest_common_divisor(3, 5)
22 1
23 >>> greatest_common_divisor(16, 4)
24 4
25 >>> greatest_common_divisor(-3, 9)
26 3
27 >>> greatest_common_divisor(9, -3)
28 3
29 >>> greatest_common_divisor(3, -9)
30 3
31 >>> greatest_common_divisor(-3, -9)
32 3
33 >>> greatest_common_divisor(0, 0)
34 0
35 """
36 return abs(b) if a == 0 else greatest_common_divisor(b % a, a)
37
38
39def gcd_by_iterative(x: int, y: int) -> int:

Callers 7

is_carmichael_numberFunction · 0.90
diophantineFunction · 0.90
diophantine_all_solnFunction · 0.90
check_determinantMethod · 0.90
lcmFunction · 0.90
mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected