MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / greatest_common_divisor

Function greatest_common_divisor

maths/modular_division.py:129–151  ·  view source on GitHub ↗

Euclid's Lemma : d divides a and b, if and only if d divides a-b and b Euclid's Algorithm >>> greatest_common_divisor(7,5) 1 Note : In number theory, two integers a and b are said to be relatively prime, mutually prime, or co-prime if the only positive integer (factor

(a: int, b: int)

Source from the content-addressed store, hash-verified

127
128
129def greatest_common_divisor(a: int, b: int) -> int:
130 """
131 Euclid's Lemma : d divides a and b, if and only if d divides a-b and b
132 Euclid's Algorithm
133
134 >>> greatest_common_divisor(7,5)
135 1
136
137 Note : In number theory, two integers a and b are said to be relatively prime,
138 mutually prime, or co-prime if the only positive integer (factor) that divides
139 both of them is 1 i.e., gcd(a,b) = 1.
140
141 >>> greatest_common_divisor(121, 11)
142 11
143
144 """
145 if a < b:
146 a, b = b, a
147
148 while a % b != 0:
149 a, b = b, a % b
150
151 return b
152
153
154if __name__ == "__main__":

Callers 1

modular_divisionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected