2019-07-01 08:10:18 +00:00
|
|
|
"""Find Least Common Multiple."""
|
|
|
|
|
|
|
|
# https://en.wikipedia.org/wiki/Least_common_multiple
|
|
|
|
|
|
|
|
|
2018-11-23 16:51:07 +00:00
|
|
|
def find_lcm(num_1, num_2):
|
2019-07-01 08:10:18 +00:00
|
|
|
"""Find the LCM of two numbers."""
|
2019-07-02 04:05:43 +00:00
|
|
|
max_num = num_1 if num_1 > num_2 else num_2
|
|
|
|
lcm = max_num
|
|
|
|
while True:
|
2019-01-19 20:49:06 +00:00
|
|
|
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
|
2018-11-23 16:51:07 +00:00
|
|
|
break
|
2019-07-02 04:05:43 +00:00
|
|
|
lcm += max_num
|
2019-01-19 20:49:06 +00:00
|
|
|
return lcm
|
2018-11-23 16:51:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2019-07-01 08:10:18 +00:00
|
|
|
"""Use test numbers to run the find_lcm algorithm."""
|
2018-11-23 16:51:07 +00:00
|
|
|
num_1 = 12
|
|
|
|
num_2 = 76
|
|
|
|
print(find_lcm(num_1, num_2))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|