fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int int64_t
  4. using vi = vector<int>;
  5. #define FOR(i, a, b) for (int i = (a); i < (b); i++)
  6. #define all(x) x.begin(), x.end()
  7.  
  8. signed main() {
  9. ios::sync_with_stdio(0); cin.tie(0);
  10. const int MX = 4e5 + 5;
  11. vi p(MX);
  12. FOR(i, 2, MX) if (!p[i]) for (int j = i; j < MX; j += i) p[j] = i;
  13. int t; cin >> t; for (int tt = 1; tt <= t; tt++) {
  14. int n; cin >> n;
  15. vi a(n); for (auto& i : a) cin >> i;
  16. int pr = -1;
  17. FOR(i, 0, n) if (p[a[i]] == a[i]) pr = a[i];
  18. cout << pr << endl;
  19. if (pr == -1) {
  20. cout << 2 << endl;
  21. continue;
  22. }
  23. int good = 1;
  24. FOR(i, 0, n) {
  25. if (a[i] == pr) continue;
  26. if (p[a[i]] == a[i]) good = 0;
  27. if (a[i] % 2 and a[i] - p[a[i]] < 2 * pr) good = 0;
  28. if (a[i] % 2 == 0 and a[i] < 2 * pr) good = 0;
  29. }
  30. if (good) cout << pr << endl;
  31. else cout << -1 << endl;
  32. }
  33. }
Success #stdin #stdout 0.01s 6164KB
stdin
1
4
214093 100957 216346 235564 
stdout
100957
-1