#include <bits/stdc++.h>
using namespace std;
int n, v[200010], x, y, N = 2e5;
long long ans[200010], met[200010], cnt, ile;
vector<long long> tab[200010], t[200010];
void dfs(int w, int d) {
  met[w] = -cnt;
  ile++;
  for (int ver : tab[w]) {
    if (met[ver] == cnt) dfs(ver, d);
  }
}
int main() {
  scanf("%d", &n);
  for (int a = 1; a <= n; a++) {
    scanf("%d", &v[a]);
    t[v[a]].push_back(a);
  }
  for (int a = 1; a < n; a++) {
    scanf("%d %d", &x, &y);
    tab[x].push_back(y);
    tab[y].push_back(x);
  }
  for (int a = 1; a <= N; a++) {
    ++cnt;
    for (int b = a; b <= N; b += a) {
      for (int w : t[b]) {
        met[w] = cnt;
      }
    }
    for (int b = a; b <= N; b += a) {
      for (int w : t[b]) {
        if (met[w] != -cnt) {
          ile = 0;
          dfs(w, a);
          ans[a] += (ile * (ile - 1) / 2) + ile;
        }
      }
    }
  }
  for (int a = N; a >= 1; a--) {
    for (int b = a + a; b <= N; b += a) ans[a] -= ans[b];
  }
  for (int a = 1; a <= N; a++) {
    if (ans[a]) printf("%d %lld\n", a, ans[a]);
  }
  return 0;
}
