单点时限: 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.
5 31 34 35 86 46
36484210
1 25
25
2 4 6
12