func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const long long MOD = 1e9 + 7;   vector<int> g[N];   bool col[N];   int her[N], p[N];   set<int> s;   queue<int> q;   bool mp[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     bool bl = false;     for (int i = 0; i < (n); ++i) {       int tv;       cin >> tv;       vector<int> vc;       for (int j = 2; j * j <= tv; j++) {         if (tv % j == 0) {           int qan = 0;           while (tv % j == 0) {             tv /= j;             qan++;           }           if (qan % 2) vc.push_back(j);         }       }       if (tv != 1) vc.push_back(tv);       if (vc.size() == 0) {         cout << 1 << endl;         return 0;       }       if (vc.size() == 1) vc.push_back(1);       int z = vc[0] * vc[1];       if (mp[z]) bl = true;       mp[z] = true;       g[vc[0]].push_back(vc[1]);       g[vc[1]].push_back(vc[0]);       if (vc[0] <= 1000) s.insert(vc[0]);       if (vc[1] <= 1000) s.insert(vc[1]);     }     if (bl) {       cout << 2 << endl;       return 0;     }     int ans = INT_MAX;     for (auto tv : s) {       q.push(tv);       memset(her, 0, sizeof(her));       memset(col, 0, sizeof(col));       memset(p, 0, sizeof(p));       col[tv] = true;       her[tv] = 0;       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto to : g[v]) {           if (col[to]) {             if (to == p[v]) continue;             ans = min(ans, her[to] + her[v] + 1);             continue;           }           q.push(to);           col[to] = true;           her[to] = her[v] + 1;           p[to] = v;         }       }     }     if (ans == INT_MAX)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }   