HDOJ1019最大公约与最小公倍

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;


#define input freopen("input.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define For1(i,a,b) for (i=a;i<b;i++)
#define For2(i,a,b) for (i=a;i<=b;i++)
#define Dec(i,a,b) for (i=a;i>b;i--)
#define Dec2(i,a,b) for (i=a;i>=b;i--)
#define Sca_d(x) scanf("%d",&x)
#define Sca_s(x) scanf("%s",x)
#define Sca_c(x) scanf("%c",&x)
#define Sca_f(x) scanf("%f",&x)
#define Sca_lf(x) scanf("%lf",&x)
#define Fill(x,a) memset(x,a,sizeof(x))
#define MAXN 0x7fffffff


template <typename T>
T gcd(T a,T b)
{
return b==0?a:gcd(b,a%b);
}


template <typename T>
T lcm(T a,T b)
{
return a/gcd(a,b)*b;
}


int main() 
{
int ans,t,n,i,j,k;
cin>>t;
while(t--)
{
ans=1;
cin>>n;
For2(i,1,n)
{
Sca_d(k);
ans=lcm(ans,k);
}
cout<<ans<<endl;
}
return 0;
}


全部评论

相关推荐

FFFcaptain328:入职即送东南亚腰子之旅👿
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务