LCM of First n Natural Numbers | To calculate hcf ; to calculate lcm ; lcm ( a , b ) = ( a * b ) hcf ( a , b ) ; Assign a = lcm of n , n - 1 ; b = b - 1 ; Driver code ;  ; Function call pass n , n - 1 in function to find LCM of first n natural number
def hcf ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a NEW_LINE DEDENT return hcf ( b , a % b ) NEW_LINE DEDENT def findlcm ( a , b ) : NEW_LINE INDENT if ( b == 1 ) : NEW_LINE INDENT return a NEW_LINE DEDENT a = ( a * b ) // hcf ( a , b ) NEW_LINE b -= 1 NEW_LINE return findlcm ( a , b ) NEW_LINE DEDENT n = 7 NEW_LINE if ( n < 3 ) : NEW_LINE / * base case * / NEW_LINE INDENT print ( n ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( findlcm ( n , n - 1 ) ) NEW_LINE DEDENT