#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MXN = 200005;
ll sol[MXN];
int a[MXN], vis[MXN];
vector<int> adj[MXN];
vector<int> ver[MXN];
int dfs(int x, int d) {
  if (vis[x] == d) return 0;
  vis[x] = d;
  int ret = 1;
  for (int y : adj[x]) {
    if (a[y] % d) continue;
    if (vis[y] == d) continue;
    ret += dfs(y, d);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ver[a[i]].push_back(i);
  }
  for (int i = 2; i <= n; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (int i = 200000; i >= 1; --i) {
    for (int j = i; j <= 200000; j += i) {
      sol[i] -= sol[j];
      for (int x : ver[j]) {
        int sz = dfs(x, i);
        sol[i] += 1LL * sz * (sz + 1) / 2;
      }
    }
  }
  for (int i = 1; i <= 200000; ++i) {
    if (sol[i]) cout << i << ' ' << sol[i] << '\n';
  }
}
