#include <bits/stdc++.h>
using namespace std;
const int N = 200020;
int n;
vector<int> v[N];
vector<int> g[N];
int lab[N];
int sz;
int appear[N];
long long save[N];
int changes[N * 40];
long long curr = 0;
void recover() {
  curr = 0;
  while (sz > 0) lab[changes[sz--]] = -1;
}
int fin(int u) {
  if (lab[u] < 0) return u;
  changes[++sz] = u;
  return lab[u] = fin(lab[u]);
}
void join(int u, int v) {
  u = fin(u);
  v = fin(v);
  if (u == v) return;
  changes[++sz] = u;
  changes[++sz] = v;
  if (lab[u] > lab[v]) swap(u, v);
  curr += 1LL * lab[u] * lab[v];
  lab[u] += lab[v];
  lab[v] = u;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    v[x].push_back(i);
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  memset(lab, -1, sizeof lab);
  for (int i = 200000; i >= 1; --i) {
    recover();
    for (int j = i; j < N; j += i) {
      save[i] -= (j > i) * (save[j]);
      for (int x : v[j]) {
        save[i]++;
        appear[x] = 1;
        for (int y : g[x]) {
          if (appear[y]) join(x, y);
        }
      }
    }
    save[i] += curr;
    for (int j = i; j < N; j += i) {
      for (int x : v[j]) appear[x] = 0;
    }
  }
  for (int i = 1; i < N; ++i) {
    if (save[i]) printf("%d %lld\n", i, save[i]);
  }
  return 0;
}
