除了比较常见的gcd函数以外,lcm函数返回的是一个最小公倍数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define sd(a) scanf("%d",&a)
#define mem0(a) memset(a,0,sizeof(a))
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int mod = 1e9+7;
const int maxn=30;
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)
{
int temp = gcd(a,b);
return a/temp*b;
}
int main()
{
int t,n,temp;
int ans;
sd(t);
while(t--)
{
sd(n);
sd(ans);
for(int i = 0;i <n-1;i++){
sd(temp);
ans = lcm(ans,temp);
}
cout<<ans<<endl;
}
return 0;
}
来源:CSDN
作者:葉子曦
链接:https://blog.csdn.net/qq_42937838/article/details/104780655