#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 1;
long long f[MAXN], ans[MAXN];
int par[MAXN], mb[MAXN], sz[MAXN], w[MAXN];
vector<int> di[MAXN], arr[MAXN], adj[MAXN];
inline int qry(int x) { return x == par[x] ? x : par[x] = qry(par[x]); }
int main() {
  for (int i = 2; i * i < MAXN; i++)
    if (!par[i])
      for (int j = i * i; j < MAXN; j += i) par[j] = i;
  for (int i = 1; i < MAXN; i++) {
    mb[i] = -1;
    int j = i;
    while (j > 0 && par[j] > 0) {
      if (j % (par[j] * par[j]) == 0) {
        mb[i] = 0;
        break;
      }
      j /= par[j];
      mb[i] *= -1;
    }
    for (int j = i; j < MAXN; j += i) di[j].push_back(i);
  }
  mb[1] = 1;
  int n, mx = 0;
  scanf("%d", &(n));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(w[i]));
    for (int j : di[w[i]]) {
      f[j]++;
      arr[j].push_back(i);
    }
    mx = max(mx, w[i]);
  }
  for (int j = 1; j < n; j++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = mx; i > 0; i--) {
    if (f[i] == 0) continue;
    for (int j : arr[i]) par[j] = j, sz[j] = 1;
    for (int j : arr[i]) {
      int u = qry(j), v;
      for (int k : adj[j]) {
        if (w[k] % i != 0 || (v = qry(k)) == u) continue;
        par[v] = u;
        f[i] += (long long)sz[u] * (long long)sz[v];
        sz[u] += sz[v];
      }
    }
    for (int j = i, cnt = 1; j <= mx; j += i, cnt++) ans[i] += mb[cnt] * f[j];
  }
  for (int i = 1; i <= mx; i++)
    if (ans[i]) printf("%d %I64d\n", i, ans[i]);
  return 0;
}
