#include <bits/stdc++.h>
using namespace std;
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
vector<int> a, vis;
vector<long long int> ans;
vector<vector<int> > ed, h;
int cnt, n, m, tim;
void dfs(int cur, int d) {
  cnt++;
  vis[cur] = tim;
  for (auto i : ed[cur])
    if (vis[i] != tim && a[i] % d == 0) dfs(i, d);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ed.resize(n + 1);
  a = vis = vector<int>(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  ans.resize(m + 1);
  h.resize(m + 1);
  for (int i = 1; i <= n; i++) h[a[i]].push_back(i);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    ed[u].push_back(v);
    ed[v].push_back(u);
  }
  for (int i = m; i >= 1; i--) {
    tim++;
    for (int j = i; j <= m; j += i)
      for (auto k : h[j]) {
        if (vis[k] != tim) {
          cnt = 0;
          dfs(k, i);
          ans[i] += (long long int)cnt * (cnt + 1) / 2;
        }
      }
    for (int j = i + i; j <= m; j += i) ans[i] -= ans[j];
  }
  for (int i = 1; i <= m; i++)
    if (ans[i]) cout << i << " " << ans[i] << "\n";
}
