/************************************************ * Author :Running_Time * Created Time :2015-9-5 19:48:28 * File Name :B.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 5e4 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int a[110]; map<int, int> cnt; void factorize(int n) { for (int i=2; i*i<=n; ++i) { while (n % i == 0) { n /= i; cnt[i]++; } } if (n != 1) cnt[n]++; } int main(void) { int T; scanf ("%d", &T); while (T--) { cnt.clear (); int n; scanf ("%d", &n); for (int i=1; i<=n; ++i) { scanf ("%d", &a[i]); } for (int i=1; i<=n; ++i) { factorize (a[i]); } map<int, int>::iterator it; vector<int> ans; for (it=cnt.begin (); it!=cnt.end (); ++it) { if (it->second) { for (int i=1; i<=it->second; ++i) { ans.push_back (it->first); if (ans.size () == 2) break; } } if (ans.size () == 2) break; } if (ans.size () != 2) puts ("-1"); else { printf ("%I64d\n", ans[0] * 1ll * ans[1]); } } return 0; }
时间: 2024-10-15 21:04:06