fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define ld long double
  5. #define st first
  6. #define nd second
  7. #define pb push_back
  8. #define fin(a, n) for(int i = a; i < n; i++)
  9. #define fjn(a, n) for(int j = a; j < n; j++)
  10. #define all(a) a.begin(),a.end()
  11. #define allr(a) a.rbegin(),a.rend()
  12. #define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
  13.  
  14. using namespace std;
  15.  
  16. const int N = 100;
  17. const int MOD = 1000000007;
  18.  
  19. string di[] = {"D","L", "U", "R", "UL", "UR", "DL", "DR"};
  20. int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
  21. int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
  22.  
  23. vector<int> primes;
  24. vector<bool> is_prime(105, true);
  25. void sieve(ll n) {
  26. is_prime[0] = is_prime[1] = false;
  27. for(ll i = 2; i < n; i++) {
  28. if(is_prime[i]) {
  29. primes.pb(i);
  30. for(ll j = i*i; j < n; j += i) {
  31. is_prime[j] = false;
  32. }
  33. }
  34. }
  35. }
  36.  
  37. void solve() {
  38. int n; cin >> n;
  39. vector<ll> v(n);
  40. fin(0, n) cin >> v[i];
  41. sort(all(v));
  42. for (auto x : primes) {
  43. for (auto i : v) {
  44. if (i % x != 0) {
  45. return void(cout << x << '\n');
  46. }
  47. }
  48. }
  49. cout << "-1\n";
  50. }
  51.  
  52. int main() {
  53. FAST;
  54. #ifndef ONLINE_JUDGE
  55. freopen("input.txt", "r", stdin);
  56. freopen("output.txt", "w", stdout);
  57. #endif
  58. int tt = 1; cin >> tt;
  59. while (tt--) {
  60. sieve(100);
  61. //cout << "Case #" << c++ << ": ";
  62. solve();
  63. }
  64. return 0;
  65. }
Success #stdin #stdout 0.02s 5284KB
stdin
Standard input is empty
stdout
-1