Untitled

 avatar
unknown
c_cpp
a month ago
813 B
7
Indexable
// clang-format off
#include <bits/stdc++.h>
using namespace std;

#define FIN(x) freopen(x, "r", stdin)
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0)
#define SZ(x) (sizeof(x) / sizeof(*x))
#define endl '\n'
typedef long long ll;

template <typename T> void print(T &v) {
  for (auto x : v)
    cout << x << ' ';
  cout << endl;
}
// clang-format on

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  ll g = 0;
  for (ll x : a)
    g = gcd(g, x);

  if (g == 1) {
    cout << 0 << endl;
  } else if (gcd(g, n) == 1) {
    cout << 1 << endl;
  } else if (gcd(g, n - 1) == 1) {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }
}
int main() {
  // FIN("input.txt");
  FASTIO;

  int t;
  cin >> t;
  while (t--)
    solve();

  return 0;
}
Editor is loading...
Leave a Comment