Answer to Question #256450 in Python for rasi

Question #256450

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


1
Expert's answer
2021-10-30T10:37:18-0400
# 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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS