HDU-2028

Lowest Common Multiple Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29031    Accepted Submission(s): 11773


Problem Description
求n个数的最小公倍数。
 
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
 
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
 
Sample Input
2 4 6
3 2 5 7
 
Sample Output
12
70
 
该题与最小公倍数的求法有关http://www.cnblogs.com/leiyuxiang/articles/3494977.html
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <math.h>
 5 
 6 int a[1005];
 7 
 8 int gcd(int a,int b)
 9 {
10     return a%b==0?b:gcd(b,a%b);
11 }
12 
13 int main()
14 {
15     int N;
16     while(scanf("%d",&N)!=EOF)
17     {
18         for(int i=1;i<=N;i++)
19             scanf("%d",&a[i]);
20         for(i=2;i<=N;i++)
21         {
22             a[i]=a[i]/gcd(a[i],a[i-1])*a[i-1];
23         }
24         printf("%d
",a[i-1]);
25     }
26     return 0;
27 }
原文地址:https://www.cnblogs.com/leiyuxiang/p/3494969.html