题目:HDU2028 Lowest Common Multiple Plus
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2028
要点:
- 在题目的诱导下没怎么像就用了int,结果计算最大公约数时越界(#°Д°) !
- 这是道水题 ( ′д` )…
- Σ(っ °Д °;)っ 我更水。
#include<stdio.h>
#include<stdlib.h>
int LCM(int a,int b)
{
int x;
while (a%b)
{
x = b;
b = a%b;
a = x;
}
return b;
}
int main()
{
int a[101], s = 1, n, i;
while(scanf("%d", &n)!=EOF)
{
s = 1;
for(i=0;i<n;i++)
scanf("%d", &a[i]);
for(i=0;i<n;i++)
s = s/LCM(s,a[i])*a[i];
printf("%d\n", s);
}
}