fork(1) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int t, n;
  8. scanf ("%d", &t);
  9. for (t; t > 0; --t)
  10. {
  11. int a[100000];
  12. scanf ("%d", &n);
  13. for (int i = 0; i < n; ++i)
  14. {
  15. scanf ("%d", &a[i]);
  16. }
  17. sort (a, a + n);
  18. for (int j = 2; j <= a[0]; ++j)
  19. {
  20. int ans = 0;
  21. for (int i = 0; i < n; ++i)
  22. {
  23. if (a[i] % j != 0)
  24. {
  25. break;
  26. }
  27. else
  28. {
  29. ans = ans + 1;
  30. }
  31. }
  32. if (ans == n)
  33. {
  34. printf ("%d\n", j);
  35. break;
  36. }
  37. else
  38. {
  39. printf ("%d\n", -1);
  40. break;
  41. }
  42. }
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0s 3620KB
stdin
5
1
1
2
2 6
3
4 9 12
4 
4 4 8 12
5
10 20 1000000 55 45
stdout
2
-1
2
-1