http://acm.hdu.edu.cn/showproblem.php?pid=2028
求n个数的最小公倍数
注意换成a/gcd(a,b)避免越界
#include<cstdio>
#include<cstring>
int gcd(int a,int b){
if(b==0) return a;
else return gcd(b,a % b);
}
int lcm(int a,int b){
return a/gcd(a,b)*b;
}
int main(){
int n,ans,num;
while(scanf("%d",&n)!=EOF){
ans=1;
for(int i=0;i<n;i++){
scanf("%d",&num);
ans=lcm(ans,num);
}
printf("%d\n",ans);
}
return 0;
}