#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  char c;
  int num = 0, flg = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flg = -1;
  while (c >= '0' && c <= '9') {
    num = num * 10 + c - 48;
    c = getchar();
  }
  return num * flg;
}
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
vector<pair<int, int> > e[200005];
int a[200005], fa[200005], siz[200005];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
long long ans, f[200005], G[200005];
int prime[200005], tot, mu[200005];
bool vis[200005];
void shai() {
  int i, j, lim = 200000;
  vis[1] = 1;
  mu[1] = 1;
  for (i = 2; i <= lim; i++) {
    if (!vis[i]) {
      prime[++tot] = i;
      mu[i] = -1;
    }
    for (j = 1; j <= tot; j++) {
      int tmp = i * prime[j];
      if (tmp > lim) break;
      vis[tmp] = 1;
      if (i % prime[j] == 0) {
        mu[tmp] = 0;
        break;
      }
      mu[tmp] = -mu[i];
    }
  }
}
int main() {
  int n, m = 0, i, j, k, u, v, g, p, q;
  n = gi();
  shai();
  for (i = 1; i <= n; i++) a[i] = gi(), m = max(m, a[i]), G[a[i]]++;
  for (i = 1; i < n; i++) {
    u = gi();
    v = gi();
    g = gcd(a[u], a[v]);
    e[g].push_back(make_pair(u, v));
  }
  for (i = 1; i <= m; i++) {
    for (j = i; j <= m; j += i) {
      for (k = 0; k < int(e[j].size()); k++) {
        u = e[j][k].first;
        v = e[j][k].second;
        fa[u] = u;
        fa[v] = v;
        siz[u] = siz[v] = 1;
      }
    }
    for (j = i; j <= m; j += i) {
      for (k = 0; k < int(e[j].size()); k++) {
        u = e[j][k].first;
        v = e[j][k].second;
        p = find(u);
        q = find(v);
        if (p != q) {
          fa[q] = p;
          f[i] += 1ll * siz[p] * siz[q];
          siz[p] += siz[q];
        }
      }
    }
  }
  for (i = 1; i <= m; i++) {
    for (j = 2 * i; j <= m; j += i) f[i] += f[j] * mu[j / i];
    if (f[i] || G[i]) printf("%d %lld\n", i, f[i] + G[i]);
  }
}
