func_code_string: #include <bits/stdc++.h>   using namespace std;   const int M = 1000001;   int n, m, k, a[M], ver[M], nex[M], head[M], cnt, fa[M], dp[M], tmp[M], sz[M];   vector<int> v[M];   long long d[M];   void add(int x, int y) {     ver[++cnt] = y, nex[cnt] = head[x], head[x] = cnt;     ver[++cnt] = x, nex[cnt] = head[y], head[y] = cnt;   }   void dfs(int x, int f) {     fa[x] = f;     dp[x] = dp[f] + 1;     for (int i = head[x]; i; i = nex[i]) {       if (ver[i] == f) continue;       dfs(ver[i], x);     }   }   bool cmp(int a, int b) { return dp[a] > dp[b]; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &a[i]), v[a[i]].push_back(i), m = max(m, a[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);     }     dfs(1, 0);     for (int i = 1; i <= m; i++) {       int cnt = 0;       for (int j = i; j <= m; j += i) {         for (int l = 0; l < v[j].size(); l++) tmp[++cnt] = v[j][l];       }       sort(tmp + 1, tmp + 1 + cnt, cmp);       d[i] = cnt;       for (int j = 1; j <= cnt; j++) sz[tmp[j]] = 1;       for (int j = 1; j <= cnt; j++) {         int x = tmp[j], f = fa[x];         if (!sz[f]) continue;         d[i] = (d[i] + (long long)sz[x] * sz[f]);         sz[f] += sz[x];       }       for (int j = 1; j <= cnt; j++) sz[tmp[j]] = 0;     }     for (int i = m; i >= 1; i--)       for (int j = i + i; j <= m; j += i) d[i] -= d[j];     for (int i = 1; i <= m; i++)       if (d[i]) printf( %d %lld n , i, d[i]);   }   