import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; public class Main implements Runnable { //Runnableを実装する public static void main(String[] args) { // new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行 new Main().run(); } long gcd(long a, long b) { return a==0?b:gcd(b%a, a); } class DSU { int[] parent; public DSU(int n) { parent=new int[n]; Arrays.fill(parent, -1); } int root(int x) { return parent[x] < 0 ? x : (parent[x]=root(parent[x])); } boolean equiv(int x, int y) { return root(x)==root(y); } void union(int x, int y) { x=root(x);y=root(y); if (x==y) return; if (parent[x] < parent[y]) { x^=y;y^=x;x^=y; } parent[y]+=parent[x]; parent[x]=y; } } final int AMAX=100000; public void run() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); long[] A=new long[N]; ArrayList[] list=new ArrayList[AMAX+1]; ArrayList[] rev=new ArrayList[AMAX+1]; for (int i=0;i<=AMAX;++i) list[i]=new ArrayList<>(); for (int i=0;i<=AMAX;++i) rev[i]=new ArrayList<>(); for (int i=0;i A[i] * A[dst] / gcd) { e[src][1] = dst; e[src][2] = A[i] * A[dst] / gcd; } } if (dst == -1) continue; int dst_root=dsu.root(dst); for (int i : list[gcd]) { if (dsu.equiv(i, dst)) continue; if (e[dst_root][1] == -1 || e[dst_root][2] > A[i] * A[dst] / gcd) { e[dst_root][1] = i; e[dst_root][2] = A[i] * A[dst] / gcd; } } } Arrays.sort(e, (x, y) -> Long.compare(x[2], y[2])); for (int i=0;i Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }