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

Function lcm

project_euler/problem_005/sol2.py:21–37  ·  view source on GitHub ↗

Least Common Multiple. Using the property that lcm(a, b) * greatest_common_divisor(a, b) = a*b >>> lcm(3, 15) 15 >>> lcm(1, 27) 27 >>> lcm(13, 27) 351 >>> lcm(64, 48) 192

(x: int, y: int)

Source from the content-addressed store, hash-verified

19
20
21def lcm(x: int, y: int) -> int:
22 """
23 Least Common Multiple.
24
25 Using the property that lcm(a, b) * greatest_common_divisor(a, b) = a*b
26
27 >>> lcm(3, 15)
28 15
29 >>> lcm(1, 27)
30 27
31 >>> lcm(13, 27)
32 351
33 >>> lcm(64, 48)
34 192
35 """
36
37 return (x * y) // greatest_common_divisor(x, y)
38
39
40def solution(n: int = 20) -> int:

Callers 1

solutionFunction · 0.85

Calls 1

greatest_common_divisorFunction · 0.90

Tested by

no test coverage detected