Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to find least common multiple of two numbers in Python

"""
Absolute value of product of two numbers
is equal to product of GCD and LCM
gcd(a, b) * lcm(a, b) = |a*b|
=> lcm(a, b) = |a*b|/gcd(a, b)
"""
import math

def lcm(a, b):
    if a == 0 or b == 0:
        return 0
    else:
        gcd = math.gcd(a, b)
        return abs(a * b) / gcd

print(int(lcm(12, 18)))  # 36
Comment

PREVIOUS NEXT
Code Example
Python :: find location of library python linux 
Python :: django settings variables 
Python :: python plot lines with dots 
Python :: python open file exception 
Python :: como eliminar palabras repetidos de una lista python 
Python :: tkinter background color 
Python :: pprint python 
Python :: get the number of today week python 
Python :: remove x label matplotlib 
Python :: cv show image python 
Python :: import excel file to python 
Python :: how to get data in treeview in tkiter 
Python :: how to create a car game using python 
Python :: button images in tkinter 
Python :: matplotlib x axis at the top 
Python :: save dataframe to csv without index 
Python :: ionic python2 Error: not found: python2 
Python :: python get command line arguments 
Python :: how to concat csv files python 
Python :: python requests.get pdf An appropriate representation of the requested resource could not be found 
Python :: get request python 
Python :: python program to print list vertically without using loop 
Python :: clear console in python 
Python :: How to extract numbers from a string in Python? 
Python :: access to numbers in classification_report - sklearn 
Python :: .get python 
Python :: value count a list python 
Python :: pandas split dataframe to train and test 
Python :: seaborn plot dpi 
Python :: sum of a column in pandas 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =