#include <bits/stdc++.h>
using namespace std;
map<int, long long> ans, re, now;
int n, h[200005], tot, mp[200005], siz[200005], mz[200005], rem[200005], cnt;
bool vis[200005];
struct DX {
  int v, p;
} dx[400005];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void add(int u, int v) {
  dx[tot].p = h[u];
  dx[tot].v = v;
  h[u] = tot++;
}
void dfs_G(int u, int fx) {
  siz[u] = 1;
  rem[++cnt] = u;
  mz[u] = 0;
  for (int i = h[u]; ~i; i = dx[i].p) {
    int v = dx[i].v;
    if (v == fx || vis[v]) continue;
    dfs_G(v, u);
    siz[u] += siz[v];
    mz[u] = max(mz[u], siz[v]);
  }
}
int fd_G(int u) {
  cnt = 0;
  dfs_G(u, u);
  for (int i = 1; i <= cnt; i++)
    if (mz[rem[i]] <= siz[u] / 2 && siz[u] - siz[rem[i]] <= siz[u] / 2)
      return rem[i];
}
void dfs(int u, int fx, int gc) {
  re[gc = gcd(gc, mp[u])]++;
  for (int i = h[u]; ~i; i = dx[i].p) {
    int v = dx[i].v;
    if (v == fx || vis[v]) continue;
    dfs(v, u, gc);
  }
}
void sol(int u) {
  u = fd_G(u);
  vis[u] = 1;
  now[mp[u]] = 1;
  ans[mp[u]] += 1;
  for (int i = h[u]; ~i; i = dx[i].p) {
    int v = dx[i].v;
    if (vis[v]) continue;
    dfs(v, 0, mp[u]);
    for (map<int, long long>::iterator it = now.begin(); it != now.end(); it++)
      for (map<int, long long>::iterator ti = re.begin(); ti != re.end(); ti++)
        ans[gcd(it->first, ti->first)] += it->second * ti->second;
    for (map<int, long long>::iterator ti = re.begin(); ti != re.end(); ti++)
      now[ti->first] += ti->second;
    re.clear();
  }
  now.clear();
  for (int i = h[u]; ~i; i = dx[i].p) {
    int v = dx[i].v;
    if (vis[v]) continue;
    sol(v);
  }
}
int main() {
  memset(h, -1, sizeof(h));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &mp[i]);
  int a, b;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    add(a, b);
    add(b, a);
  }
  sol(1);
  for (map<int, long long>::iterator it = ans.begin(); it != ans.end(); it++)
    printf("%d %lld\n", it->first, it->second);
  return 0;
}
