#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) ll gcd(ll a,ll b) { while (b) { a %= b; swap(a,b); } return a; } int const MAX_N = 1000; vector prime; vector is_prime(MAX_N,true); void Eratosthenes() { is_prime[0] = is_prime[1] = false; for (ll i = 2;i*i < MAX_N;++i) if (is_prime[i]) for (ll j = 2*i;j < MAX_N;j += i) is_prime[j] = false; for (ll i = 0;i < MAX_N;++i) if (is_prime[i]) prime.push_back(i); } int main() { Eratosthenes(); int n;cin >> n; vector a(1000000),c; for (int i = 0;i < n;++i) cin >> a[i]; c = a; for (int i = 0;i < 19;++i) for (int j = 0;j < n;++j) if (!(j&(1< -1) { if (c[i|(1< -1) c[j] += c[i|(1< mp; for (int i = 0;i < n;++i) if (a[i] > -1) { map mp2; mp2[1]++; for (ll j : prime) { if (j*j > a[i]) break; while (a[i]%j == 0) mp2[j]++,a[i] /= j; } if (a[i] > 1) mp2[a[i]]++; for (ll j : prime) { if (j*j > c[i]) break; while (c[i]%j == 0) mp2[j]++,c[i] /= j; } if (c[i] > 1) mp2[c[i]]++; if (mp.size() == 0) mp = mp2; else for (auto& p : mp) p.second = min(p.second,mp2[p.first]); } ll ans = 1; for (auto p : mp) for (int i = 0;i < p.second;++i) ans *= p.first; cout << (mp.size() ? ans : -1) << endl; }