About 5,510,000 results
Open links in new tab
  1. Python Program to Find LCM of Two Numbers - GeeksforGeeks

    Jul 2, 2024 · In this example, the function LCM(a, b) calculates the Least Common Multiple (LCM) of two numbers a and b by iterating through multiples of the greater number within a range up to their product, and returns the first multiple that is divisible by the smaller number.

  2. Python Program to Find LCM

    Write a function to calculate the lowest common multiple (LCM) of two numbers. The formula to calculate LCM is lcm(a, b) = abs(a*b) // gcd(a, b), where gcd() is the greatest common divisor of a and b. For example, with inputs 12 and 15, the output should be …

  3. Program to find LCM of two numbers - GeeksforGeeks

    Feb 14, 2025 · # Python program to find LCM of two numbers # Function to return LCM of two numbers def LCM (a, b): greater = max (a, b) smallest = min (a, b) for i in range (greater, a * b + 1, greater): if i % smallest == 0: return i # Driver program to test above function if __name__ == '__main__': a = 10 b = 5 print ("LCM of", a, "and", b, "is", LCM (a, b))

  4. Python Program to Find LCM (3 Different Ways)

    Learn 3 different ways to find the LCM in Python. Explore methods using loops, GCD, and Prime Factorization with easy-to-follow examples.

  5. Python Program to Find the LCM of Two Numbers

    This is a Python Program to find the LCM of two numbers. The program takes two numbers and prints the LCM of two numbers. 1. Take in both the integers and store it in separate variables. 2. Find which of the integer among the two is smaller and store it in a separate variable. 3. Use a while loop whose condition is always True until break is used.

  6. Python: Least common multiple (LCM) of two positive integers

    Apr 16, 2025 · Use functools.reduce (), math.gcd () and lcm (x,y) = x * y / gcd (x,y) over the given list. # Import the 'reduce' function from the 'functools' module and the 'gcd' function from the 'math' module. # Define a function 'lcm' that calculates the least …

  7. Python Programs to Find HCF and LCM of two numbers - PYnative

    Mar 31, 2025 · In Python, you can use the math module to find the Highest Common Factor (HCF) and the Least Common Multiple (LCM) of two numbers. The math module provides built-in functions math.gcd() for HCF (or GCD).

  8. Built-in module to calculate the least common multiple

    Nov 18, 2020 · I've created this one for receiving an arbitrary number of parameters and thus calculate the lcm. from math import gcd, prod def lcm(*list): return abs(prod(list)) // gcd(*list) lcm(1,44,22)

  9. Python LCM – 2 Ways to find LCM - The Crazy Programmer

    In this article, we’ll see different ways to find LCM in Python with program examples. Basically LCM is a smallest number that is divisible by both numbers (or all). Let us see how we can find lcm of two numbers in python.

  10. Python Program To Find LCM Of Two Numbers - Unstop

    To find the LCM of two numbers in Python, we can use the LCM formula inside a for loop, a while loop, or a recursive function. Alternatively, we can use the math module's built-in functions gcd () and lcm ().

  11. Some results have been removed
Refresh