#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int LIM = 200010;
int a[LIM], father[LIM], fa[LIM];
long long size[LIM];
vector<int> lis[LIM], E[LIM];
long long res[LIM];
int find(int x) { return (x == father[x] ? x : find(father[x])); }
void DFS(int x, int pre) {
  for (auto y : E[x]) {
    if (y == pre) continue;
    fa[y] = x;
    DFS(y, x);
  }
}
int main() {
  int n, u, v;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), lis[a[i]].push_back(i);
  for (int i = 1; i < n; ++i) {
    scanf("%d %d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  DFS(1, -1);
  for (int i = 1; i <= 200000; ++i) {
    for (int j = i; j <= 200000; j += i) {
      res[i] += lis[j].size();
      for (auto x : lis[j]) {
        father[x] = x;
        size[x] = 1;
      }
    }
    for (int j = i; j <= 200000; j += i) {
      for (auto x : lis[j]) {
        if (x == 1) continue;
        if (father[fa[x]] == 0) continue;
        int a = find(x), b = find(fa[x]);
        res[i] += size[a] * size[b];
        father[a] = b, size[b] += size[a];
      }
    }
    for (int j = i; j <= 200000; j += i)
      for (auto x : lis[j]) father[x] = size[x] = 0;
  }
  for (int i = 200000; i >= 1; --i)
    for (int j = 2 * i; j <= 200000; j += i) res[i] -= res[j];
  for (int i = 1; i <= 200000; ++i)
    if (res[i]) printf("%d %I64d\n", i, res[i]);
  return 0;
}
