Language: C++

#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// coordinate compression
struct X {
  typedef int T;
  vector<T> d;
  inline void add(T x) { d.pb(x);}
  void init() {
    sort(rng(d));
    d.erase(unique(rng(d)), d.end());
  }
  inline int size() { return sz(d);}
  inline int operator[](T x) { return upper_bound(rng(d),x)-d.begin()-1;}
};
//

// Lowlink
// bridge : v->u, ord[u]==low[u]
// articulation : exist ord[v]<=low[u] (root:*2)
struct Lowlink {
  int n, k;
  vvi to, st, br, g, gr;
  vi ord, low, art, gv;
  Lowlink(int n=0):n(n),to(n),st(n),br(n),ord(n,-1),low(n),art(n){}
  void add(int a, int b) {
    to[a].pb(b); st[a].pb(0);
    to[b].pb(a); st[b].pb(0);
  }
  void dfs(int v, int p=-1) {
    ord[v] = low[v] = k++;
    rep(i,sz(to[v])) {
      int u = to[v][i];
      if (u == p) continue;
      if (ord[u] == -1) {
        st[v][i] = 1;
        dfs(u,v);
        mins(low[v],low[u]);
      } else {
        st[v][i] = -1;
        mins(low[v],ord[u]);
      }
    }
  }
  void init() {
    k = 0;
    dfs(0);
    rep(i,n)rep(j,sz(to[i])) {
      int v = i, u = to[i][j];
      if (ord[v] > ord[u]) swap(v,u);
      br[i].pb(ord[u] == low[u]);
    }
    rep(i,n) {
      int cnt = 0;
      rep(j,sz(to[i])) {
        if (st[i][j] == 1 && ord[i] <= low[to[i][j]]) ++cnt;
      }
      art[i] = cnt > !i;
    }
    g = vvi(1);
    gr = vvi(1);
    gv = vi(n);
    gfs(0,0);
    k = sz(g);
  }
  void gfs(int v, int r) {
    gr[r].pb(v);
    gv[v] = r;
    rep(i,sz(to[v])) {
      if (st[v][i] != 1) continue;
      if (br[v][i]) {
        g[r].pb(sz(g));
        g.pb(vi(1,r));
        gr.pb(vi());
        gfs(to[v][i],sz(g)-1);
      } else gfs(to[v][i],r);
    }
  }
};
//


int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  rep(i,n) {
    scanf("%d",&a[i]);
  }
  X xs;
  vvi a;
  rep(i,n) {
    int na = a[i];
    for (int j = 2; j*j <= na; ++j) {
      if (na%j) continue;
      xs.add(j);
      while (na%j == 0) {
        na /= j;
      }
    }
    if (na != 1) xs.add(na);
  }
  int m = sz(xs);
  xs.init();
  map<int,vi> mp;
  rep(i,n) {
    vi ps;
    rep(j,m) {
      if (a[i]%xs.d[j] == 0) ps.pb(j);
    }
    mp[a[i]] = ps;
  }

  vi ans;
  while (sz(a)) {
    n = sz(a);
    sort(rng(a));
    Lowlink g(n+m);
    rep(i,n) {
      vi ps = mp[a[i]];
      for (int j : ps) g.add(i,n+j);
    }
    g.init();
    
  }
  cout<<ans<<endl;
  return 0;
}






















Compiler output:
a.cc: In function 'int main()':
a.cc:152:7: error: conflicting declaration 'vvi a'
  152 |   vvi a;
      |       ^
a.cc:147:6: note: previous declaration as 'vi a'
  147 |   vi a(n);
      |      ^