Question #256450

18. Write a code to find the smallest divisible number of a given number(here number is input).


Expert's answer

# Python program to find the smallest number evenly  
# divisible by all number 1 to n 

import math


   
# Returns the lcm of first n numbers 

def lcm(n): 


    ans = 1


    for i in range(1, n + 1): 


        ans = int((ans * i)/math.gcd(ans, i))         


    return ans 


   
# main 

n = 20


print (lcm(n))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS