Problem Description 求n个数的最小公倍数。 Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。 Output 为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。 Sample

#include<stdio.h>
int main()
{
int x_y(int x,int y);
int i,n,a[1111],s;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
if(n==1)printf("%d\n",a[0]);
else
{
s=x_y(a[0],a[1]);
for(i=1;i<n;i++)
s=x_y(s,a[i]);
}
printf("%d\n",s);
}
return 0;
}
int x_y(int x,int y)
{
int a,b,t,m;
a=x;b=y;
if(x>y)
{t=x;x=y;y=t;}
for(;x!=0;)
{
t=y%x;
y=x;
x=t;
}
m=(a/y)*b;
return m;
}

 

posted @ 2012-06-10 16:16  尔滨之夏  阅读(7377)  评论(0编辑  收藏  举报