- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Find LCM using Python?
LCM (Least common multiple) of two (or more) numbers is a number which is the smallest number that is divisible by both (or all).
First we find the larger number of two given numbers. Starting from it we try and find the first number that is divisible by both, which is LCM
Example
x=12 y=20 if x > y: greater = x else: greater = y while(True): if((greater % x == 0) and (greater % y == 0)): lcm = greater break greater += 1 print ("LCM of {} and {}={}".format(x,y,lcm))
Output
The result is −
LCM of 12 and 20=60
Advertisements