#include <bits/stdc++.h>
using namespace std;
const int M=; int gcd(int a, int b)
{
return a%b== ? b:gcd(b, a%b);
} int lcm(int a, int b)
{
return a/gcd(a, b)*b;
} int main()
{
int n;
int a[M];
while(cin>>n)
{
for(int i=;i<=n;i++)
cin>>a[i];
int ans=a[];
for(int i=;i<=n;i++)
ans=lcm(ans,a[i]);
cout<<ans<<endl;
}
return ;
}
编译的时候卡在error: 'cin' was not declared in this scope
以为头文件打错了,顺手改成#include<cstdio>,还是不对,索性又改回来了,然后编译成功......
int gcd(int a, int b)
{
return a%b==0 ? b:gcd(b, a%b);
}
int lcm(int a, int b)
{
return a/gcd(a, b)*b;
}
这个写法挺简单的,码一下。