题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2028
题意:
中文题目,意思很明白就是求多个数的最小公倍数。
参考代码一:
#include <iostream>
using namespace std;
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 i,x,y,n;
while(cin>>n)
{
x=1;
for(i=0;i<n;i++)
{
cin>>y;
x=lcm(x,y);
}
cout<<x<<endl;
}
return 0;
}
参考代码二:
#include<stdio.h>
int main()
{
int s;
__int64 a,b,temp,k;
while(~scanf("%d",&s))
{
s--;
scanf("%I64d",&a);
while(s--)
{
scanf("%I64d",&b);
k=a*b;
temp=0;
while(b)
{
if(a>b)
{
temp=a;
a=b;
}
else
temp=b;
b=temp%a;
}
a=k/a;
}
printf("%I64d\n",a);
}
return 0;
}