#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, par[maxn], rot[maxn], sz[maxn];
vector<int> divs[maxn], g[maxn], subt[maxn], vers[maxn];
long long cnt[maxn];
void dfs(int x, int parx) {
  for (auto y : g[x])
    if (y != parx) par[y] = x, dfs(y, x);
}
int root(int x) { return rot[x] == x ? x : rot[x] = root(rot[x]); }
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 2; i < maxn; ++i) {
    for (int j = i; j < maxn; j += i) divs[j].emplace_back(i);
  }
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    for (auto d : divs[x]) vers[d].emplace_back(i + 1);
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].emplace_back(b), g[b].emplace_back(a);
  }
  g[0].emplace_back(1);
  dfs(0, 0);
  cnt[1] = 1LL * n * (n + 1) / 2;
  iota(rot, rot + n + 1, 0);
  for (int d = 2; d < maxn; ++d) {
    for (auto v : vers[d]) {
      sz[v] = 1;
      ++cnt[d];
      if (sz[par[v]]) {
        rot[v] = root(par[v]);
        cnt[d] += sz[rot[v]];
        sz[rot[v]] += sz[v];
      } else
        subt[par[v]].emplace_back(v);
      root(v);
      for (auto ch : subt[v]) {
        rot[ch] = rot[v];
        cnt[d] += 1LL * sz[rot[v]] * sz[ch];
        sz[rot[v]] += sz[ch];
      }
    }
    for (auto v : vers[d]) {
      sz[v] = 0;
      subt[par[v]].clear();
      rot[v] = v;
    }
  }
  for (int i = (maxn)-1; i >= 1; --i) {
    for (int j = i + i; j < maxn; j += i) cnt[i] -= cnt[j];
  }
  for (int i = 1; i < maxn; ++i)
    if (cnt[i]) {
      cout << i << ' ' << cnt[i] << '\n';
    }
}
