lcy
思路:没有用欧几里得算法来求,用的是stein算法试一下。最大公约数、
最小公倍数的欧几里得算法和stein算法参考博文:
http://blog.csdn.net/lianai911/article/details/42003903
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; int GCD(int a,int b) { if(a == 0) return b; if(b == 0) return a; if(~a & 1) { if(b & 1) return GCD(a>>1, b); else return GCD(a>>1, b>>1)<<1; } if(~b & 1) return GCD(a, b>>1); if(a > b) return GCD((a-b)>>1, b); return GCD((b-a)>>1,a); } int LCM(int a,int b) { return a/GCD(a,b)*b; } int main() { int N,d; while(cin >> N) { int ans = 1; for(int i = 1; i <= N; ++i) { cin >> d; ans = LCM(ans,d); } cout << ans << endl; } return 0; }