LCM function for a list of integers