How to Find LCM of Two Numbers in Python


In this example we will show how to find the least common multiple (LCM) of two numbers in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import fractions

a = int(input("Enter the first number:"))
b = int(input("Enter the second number:"))
lcd = a * b // fractions.gcd(a,b)
print("The LCM of the two numbers is ", lcd)

Output:

Enter the first number:2
Enter the second number:3
The LCM of the two numbers is  6

Enter the first number:15
Enter the second number:25
The LCM of the two numbers is  75
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments