#include <bits/stdc++.h>
using namespace std;
int n, a[200000 + 5], mu[200000 + 5], cc, good[200000 + 5], used[200000 + 5],
    q[200000 + 5], fr, bk;
long long ans1[200000 + 5], ans2[200000 + 5];
vector<int> G[200000 + 5], nbfs[200000 + 5], prime;
bool vis[200000 + 5];
void init() {
  mu[1] = 1;
  for (int i = 2; i <= 200000; i++) {
    if (!vis[i]) {
      prime.push_back(i);
      mu[i] = -1;
    }
    for (int j = 0; i * prime[j] <= 200000; j++) {
      vis[i * prime[j]] = true;
      if (i % prime[j] == 0) {
        mu[i * prime[j]] = 0;
        break;
      }
      mu[i * prime[j]] = -mu[i];
    }
  }
}
int bfs(int x, int gc) {
  fr = bk = 0;
  q[bk++] = x;
  used[x] = cc;
  while (fr < bk) {
    int z = q[fr++];
    for (int i = 0; i < G[z].size(); i++) {
      int y = G[z][i];
      if (good[a[y]] == cc && used[y] < cc) {
        used[y] = cc;
        q[bk++] = y;
      }
    }
  }
  return bk;
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    nbfs[a[i]].push_back(i);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 200000; i > 0; i--) {
    cc++;
    for (int j = i; j <= 200000; j += i) good[j] = cc;
    for (int j = i; j <= 200000; j += i)
      for (int k = 0; k < nbfs[j].size(); k++) {
        int x = nbfs[j][k];
        if (used[x] == cc) continue;
        int z = bfs(x, i);
        ans1[i] += 1ll * z * (z + 1) / 2;
      }
    for (int j = i, k = 1; j <= 200000; j += i, k++) ans2[i] += mu[k] * ans1[j];
  }
  for (int i = 1; i <= 200000; i++)
    if (ans2[i]) printf("%d %lld\n", i, ans2[i]);
}
