2021级《程序设计原理及C语言》练习题

F. LCM

单点时限: 2.0 sec

内存限制: 512 MB

In arithmetic, the least common multiple (LCM) of two integers a and b, usually denoted by LCM (a, b), is the smallest positive integer that is divisible by both a and b. For example, the LCM of 4 and 6 is 12.

Write a function LCM(), which computes the least common multiple of $n$ integers $a_1, a_2,… a_n$ ,$(1 \leq a_1, a_2,… a_n \leq 100, 1 \leq n \leq 9)$.

#include <stdio.h>
#define N 9

long long LCM(int a[], int n)
{
 // precondition: 1≤n≤9, 1≤a[i]≤100
 // postcondition: return LCM of all integers 

}

int main()
{ 
   int i,n,a[N];
   for (scanf("%d",&n),i=0;i<n;i++) scanf("%d",&a[i]);
   printf("%lld\n", LCM(a,n));
   return 0;
}

输入格式

Input $n$ in one line.

Input $a_1,a_2,…,a_n$ in another line.

输出格式

Output the least common multiple of $n$ integers in one line.

样例

Input
5
31 34 35 86 46
Output
36484210
Input
1
25
Output
25
Input
2
4 6
Output
12