#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long num = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9') num = num * 10 + c - 48, c = getchar();
  return num * flag;
}
int n, m = 200000;
int a[200005], U[200005], V[200005];
vector<int> D[200005];
long long f[200005];
int pri[200005], mu[200005], np[200005], cnt;
int fa[200005], sz[200005];
inline int gcd(int p, int q) { return q ? gcd(q, p % q) : p; }
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline void init() {
  mu[1] = 1;
  for (int i = 2; i < 200005; i++) {
    if (!np[i]) pri[++cnt] = i, mu[i] = -1;
    for (int j = 1; j <= cnt && i * pri[j] < 200005; j++) {
      np[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
      mu[i * pri[j]] = -mu[i];
    }
  }
}
int main() {
  n = getint();
  init();
  for (int i = 1; i <= n; i++) {
    a[i] = getint();
    for (int j = 1; j * j <= a[i]; j++)
      if (a[i] % j == 0) {
        f[j]++;
        if (j * j != a[i]) f[a[i] / j]++;
      }
  }
  for (int i = 1; i < n; i++) {
    U[i] = getint(), V[i] = getint();
    int tmp = gcd(a[U[i]], a[V[i]]);
    for (int j = 1; j * j <= tmp; j++)
      if (tmp % j == 0) {
        D[j].push_back(i);
        if (j * j != tmp) D[tmp / j].push_back(i);
      }
  }
  for (int d = 1; d <= m; d++) {
    for (int i = 0; i < D[d].size(); i++) {
      int u = U[D[d][i]], v = V[D[d][i]];
      fa[u] = u, sz[u] = 1, fa[v] = v, sz[v] = 1;
    }
    for (int i = 0; i < D[d].size(); i++) {
      int u = find(U[D[d][i]]), v = find(V[D[d][i]]);
      f[d] += 1ll * sz[u] * sz[v];
      sz[u] += sz[v], fa[v] = u;
    }
  }
  for (int i = 1; i <= m; i++) {
    long long ans = 0;
    for (int j = 1; j * i <= m; j++) ans += 1ll * mu[j] * f[i * j];
    if (ans) printf("%d %lld\n", i, ans);
  }
}
