标签:algo main com [] iter common 等于 turn ble
链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2028
题目要求:就是求最大公倍数,我百度了一下,最好实现的算法就是:
#include <iostream> #include<math.h> #include <iomanip> #include<cstdio> #include<string> #include<map> #include<vector> #include<list> #include<algorithm> #include<stdlib.h> #include<iterator> using namespace std; int gcd(int a,int b) { int big=a; int smal=b; int ck; if(big<smal) { ck=a; a=b; b=a; } int temp; while(smal>0) { temp=big%smal; big=smal; smal=temp; } return big; } unsigned int gys(unsigned int a,unsigned int b) { unsigned int kk; unsigned int ak=a; unsigned int bk=b; kk=ak*bk/gcd(ak,bk); return kk; } int main() { int n; while(cin>>n) { unsigned int *p; p=new unsigned int[n]; for(int i=0;i<n;i++) { cin>>p[i]; } int unsigned max_gys=p[0]; for(int j=0;j<n-1;j++) { max_gys=gys(max_gys,p[j+1]); } cout<<max_gys<<endl; delete []p; } return 0; }
杭电 2028 ( Lowest Common Multiple Plus )
标签:algo main com [] iter common 等于 turn ble
原文地址:http://www.cnblogs.com/William-xh/p/6852933.html