#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T>>;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 2e5 + 10;
const int maxS = 2e5 + 10;
int n, a[maxN], num;
vector<int> adj[maxN], vec[maxS];
vector<pair<int, int>> edges[maxS];
long long cnt[maxS], ans[maxS];
bool flag[maxN];
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
void dfs(int u) {
  flag[u] = 1;
  num++;
  for (auto &v : adj[u]) {
    if (!flag[v]) {
      dfs(v);
    }
  }
}
void solve() {
  cin >> n;
  for (int i = 1; i <= (int)(n); ++i) {
    cin >> a[i];
    vec[a[i]].emplace_back(i);
  }
  for (int i = 0; i < (int)(n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    int g = GCD(a[u], a[v]);
    edges[g].emplace_back(u, v);
  }
  for (int g = 1; g <= (int)(2e5); ++g) {
    for (int d = g; d <= 2e5; d += g) {
      for (auto &e : edges[d]) {
        int u, v;
        tie(u, v) = e;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
      }
    }
    for (int d = g; d <= 2e5; d += g) {
      for (auto &u : vec[d]) {
        if (!flag[u]) {
          num = 0;
          dfs(u);
          cnt[g] += (long long)num * (num + 1) / 2;
        }
      }
    }
    for (int d = g; d <= 2e5; d += g) {
      for (auto &u : vec[d]) {
        flag[u] = 0;
        adj[u].clear();
      }
    }
  }
  for (int i = 2e5; i; i--) {
    ans[i] = cnt[i];
    for (int j = i * 2; j <= 2e5; j += i) {
      ans[i] -= ans[j];
    }
  }
  for (int i = 1; i <= (int)(2e5); ++i) {
    if (ans[i] > 0) {
      cout << i << " " << ans[i] << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
