#K39837. Least Common Multiple of an Array

    ID: 26509 Type: Default 1000ms 256MiB

Least Common Multiple of an Array

Least Common Multiple of an Array

Given an array of positive integers, your task is to compute the Least Common Multiple (LCM) of all the numbers in the array. The LCM is the smallest positive integer that is divisible by every number in the array.

You may use the formula for two integers \(a\) and \(b\):
\(\text{lcm}(a, b)=\frac{|a \times b|}{\gcd(a, b)}\),
and extend it iteratively to compute the LCM for the entire array.

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(n\) which denotes the number of elements in the array.
  • The second line contains \(n\) space-separated positive integers.

outputFormat

Output a single integer representing the Least Common Multiple (LCM) of the input array.

## sample
3
4 6 8
24