Python: (Math) Least Common Multiple (LCM) of Counting Numbers

Post Reply
User avatar
Jason
Site Admin
Posts: 688
Joined: Tue Jul 01, 2025 10:13 am

Code: Select all

import math

	def find_the_lcm(num1, num2):
  
    		return math.lcm(num1, num2)


the_first_number = 3

the_second_number = 19

the_lcm_of_the_two_numbers = find_the_lcm(the_first_number, the_second_number)

print(f"The LCM of {the_first_number} and {the_second_number} is: {the_lcm_of_the_two_numbers}")

The LCM of Counting Numbers is found by multiplying the target numbers respectively by the counting numbers starting at 1 and then noting the lowest match. It is used when finding the sum and/or difference of fractions with different denominators.
Ex. What is the LCM of 10 and 15?
\(10: 10 * 1 = 10 \,\,\,\, 10 * 2 = 20 \,\,\,\, 10 * 3 = \underline{30}\)

\(15: 15 * 1 = 15 \,\,\,\, 15 * 2 = \underline{30}\)

\(LCM\,\,= 30\)
 

POSTREACT(ions) SUMMARY

Post Reply