#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 1;
vector<vector<int>> adjList(MAX);
vector<int> mxd(MAX);
int dfs(int nd, int md) {
  int res = 1;
  mxd[nd] = 0;
  for (int cd : adjList[nd]) {
    if (mxd[cd] == md) {
      res += dfs(cd, md);
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> div(MAX);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    div[a[i]].push_back(i);
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  vector<long long> ans(MAX);
  ans[1] = (n * (n - 1)) / 2 + n;
  for (int i = 2; i < MAX; i++) {
    vector<int> p;
    for (int j = i; j < MAX; j += i) {
      for (int k : div[j]) {
        p.push_back(k);
        mxd[k] = i;
      }
    }
    for (int nd : p) {
      if (mxd[nd] == i) {
        long long sz = (long long)dfs(nd, i);
        ans[i] += (sz * (sz - 1)) / 2 + sz;
      }
    }
  }
  for (int i = MAX - 1; i >= 1; i--) {
    for (int j = 2 * i; j < MAX; j += i) {
      ans[i] -= ans[j];
    }
  }
  for (int i = 1; i < MAX; i++) {
    if (ans[i] != 0) {
      cout << i << " " << ans[i] << '\n';
    }
  }
  return 0;
}
