```#include <iostream>#include<iomanip>#include<vector>#include<algorithm>#include<cmath>#include<string>usingnamespace std;intmain(){int n;while(cin>>n){
vector<int>a;for(int i =0; i < n; i++)//把数据存进vector里{int x;
cin >> x;
a.push_back(x);}sort(a.begin(), a.end());//排序方便找到最大的数int t =1;int num =1;int j =0;while(t){int y =1;
j++;//j每次都加一
num = a[a.size()-1]* j;//每次都把最大的数分别乘以1,2,3等等也就是jfor(int i =0; i < n -1; i++){if(num%a[i]!=0)//如果有一个数不能被整除那就不是公倍数{
y =0;}}if(y ==1)//全都可以整除就不用继续循环啦
t =0;}
cout << num << endl;}return0;}
我这个算比较麻烦的暴力解法,不过也ac啦,看有大佬有很短的利用公因数函数的代码,也贴过来吧
```cpp
#include<stdio.h>intgcd(int a,int b){if(!b)return a;returngcd(b,a%b);}intmain(){int a,p,n;while(~scanf("%d%d",&n,&p)){while(--n){scanf("%d",&a);
p *= a /gcd(p,a);}printf("%d\n", p);}}
求n个数的最小公倍数。```#include <iostream>#include<iomanip>#include<vector>#include<algorithm>#include<cmath>#include<string>using namespace std;int main(){ int n; while (cin>>n) { vector<int>a; f