hdoj 1019

来源:互联网 发布:齐鲁大学生软件大赛 编辑:程序博客网 时间:2024/05/20 01:11

链接
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;}


 

原创粉丝点击