#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int n, a[MAXN], u[MAXN], v[MAXN];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
vector<int> c[MAXN];
long long f[MAXN];
int x[MAXN], fa[MAXN], siz[MAXN];
int getfa(int u) { return u == fa[u] ? u : fa[u] = getfa(fa[u]); }
inline void merge(int j, int u, int v) {
  u = getfa(u);
  v = getfa(v);
  if (u == v) return;
  f[j] += (long long)siz[u] * siz[v];
  fa[u] = v;
  siz[v] += siz[u];
}
int mu[MAXN], prm[MAXN], pn;
bool notp[MAXN];
void table(int n) {
  notp[0] = notp[1] = 1;
  mu[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!notp[i]) {
      prm[++pn] = i;
      mu[i] = -1;
    }
    for (int j = 1; j <= pn && prm[j] * i <= n; j++) {
      notp[prm[j] * i] = 1;
      if (i % prm[j])
        mu[prm[j] * i] = -mu[i];
      else {
        mu[prm[j] * i] = 0;
        break;
      }
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 1; j * j <= a[i]; j++)
      if (!(a[i] % j)) {
        f[j]++;
        if (j * j != a[i]) ++f[a[i] / j];
      }
  }
  for (int i = 1; i < n; i++) {
    cin >> u[i] >> v[i];
    int t = gcd(a[u[i]], a[v[i]]);
    for (int j = 1; j * j <= t; j++)
      if (!(t % j)) {
        c[j].push_back(i);
        if (j * j != t) c[t / j].push_back(i);
      }
  }
  int m = 200000;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < c[i].size(); j++) {
      fa[u[c[i][j]]] = u[c[i][j]];
      siz[u[c[i][j]]] = 1;
      fa[v[c[i][j]]] = v[c[i][j]];
      siz[v[c[i][j]]] = 1;
    }
    for (int j = 0; j < c[i].size(); j++) merge(i, u[c[i][j]], v[c[i][j]]);
  }
  table(m);
  for (int k = 1; k <= m; k++) {
    long long ans = 0;
    for (int i = 1; i * k <= m; i++) ans += mu[i] * f[i * k];
    if (ans) cout << k << ' ' << ans << '\n';
  }
  return 0;
}
