现在的位置: 首页 > 综合 > 正文

hdoj 1019

2019年07月31日 ⁄ 综合 ⁄ 共 473字 ⁄ 字号 评论关闭

链接
http://acm.hdu.edu.cn/showproblem.php?pid=1019
//数学题

#include <iostream>

using namespace std;

long g(long a, long b)
{
 if (a > b) swap(a, b);
 long t;
 while (b%a) {
  t = b%a;
  b = a;
  a = t;
 }
 return a;
}
long l(long a, long b)
{
 return a / g(a, b) * b ;
}

int main()
{
 int t, n;
 long a, temp;
 int i, j;
 long *d;
 cin >> t;
 while (t--) {
  cin >> n;
  if (n == 0) {
   cout << "0" << endl;
   continue;
  }
  d = (long *)malloc(sizeof(long)*n);
  for (i = 0; i < n; i++) {
   cin >> d[i];
  }
  if (n == 1) temp = d[0];
  if (n >= 2) {
   temp = l(d[0], d[1]);
   for (i = 2; i < n; i++)
    temp = l(temp, d[i]);
  }
  cout << temp << endl;
 }
 return 0;
}

 

【上篇】
【下篇】

抱歉!评论已关闭.