fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fi first
  5. #define se second
  6. #define MOD 1000000007
  7. #define FOR(i,a,b) for (int i = (a);i <= (b);i++)
  8. #define FOD(i,a,b) for (int i = (b);i >= (a);i--)
  9. #define ALL(x) (x).begin(),(x).end()
  10. #define ii pair<int,int>
  11. #define iii pair<int,pair<int,int>>
  12. //const int MOD = 998244353;
  13. const int MAXN = 1e6 + 7;
  14. int a[MAXN],f[MAXN];
  15. int main(){
  16. ios_base::sync_with_stdio(0);
  17. cin.tie(0); cout.tie(0);
  18. //freopen("cardscore.inp","r",stdin);
  19. //freopen("cardscore.out","w",stdout);
  20. int n;cin >> n;
  21. FOR(i,1,n)cin >> a[i];
  22. FOR(i,1,n){
  23. FOR(j,2,(int)sqrt(a[i]))if (a[i] % j == 0){
  24. while(a[i] % j == 0)a[i] = a[i] / j;
  25. f[j]++;
  26. }
  27. if (a[i] > 1)f[a[i]]++;
  28. }
  29. FOR(i,2,MAXN - 1)if (f[i] == n)
  30. return cout << i,0;
  31. cout << -1;
  32. return 0^0;
  33. }
Success #stdin #stdout 0.01s 5784KB
stdin
3
1 2 3
stdout
-1