[刷题笔记]HDU2028-局部越界

题目:HDU2028  Lowest Common Multiple Plus

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2028

要点:

  1. 在题目的诱导下没怎么像就用了int,结果计算最大公约数时越界(#°Д°) !
感想:

  1. 这是道水题  (  ′д` )…
  2. Σ(っ °Д °;)っ   我更水。
代码:

#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);
	}
}


你可能感兴趣的:([刷题笔记]HDU2028-局部越界)