forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_lcm.py
More file actions
34 lines (26 loc) · 694 Bytes
/
Copy pathfind_lcm.py
File metadata and controls
34 lines (26 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Find Least Common Multiple."""
# https://en.wikipedia.org/wiki/Least_common_multiple
def find_lcm(num_1, num_2):
"""Find the least common multiple of two numbers.
>>> find_lcm(5,2)
10
>>> find_lcm(12,76)
228
"""
if num_1>=num_2:
max_num=num_1
else:
max_num=num_2
lcm = max_num
while True:
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
break
lcm += max_num
return lcm
def main():
"""Use test numbers to run the find_lcm algorithm."""
num_1 = int(input().strip())
num_2 = int(input().strip())
print(find_lcm(num_1, num_2))
if __name__ == '__main__':
main()