#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 7;
const double pi = acos(-1.0);
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = (long long)a * a % M)
    if (b & 1) ret = (long long)ret * a % M;
  return ret;
}
int A[maxn];
vector<int> edge[maxn];
int sz[maxn];
bool mark[maxn];
int minweight, root;
void dfs1(int x, int fa, int n) {
  int weight = 0;
  sz[x] = 1;
  for (int v : edge[x]) {
    if (v == fa || mark[v]) continue;
    dfs1(v, x, n);
    sz[x] += sz[v];
    weight = max(weight, sz[v]);
  }
  weight = max(weight, n - sz[x]);
  if (weight < minweight) root = x, minweight = weight;
}
unordered_map<int, int> now;
unordered_map<int, int> MP;
unordered_map<int, long long> ans;
void dfs2(int x, int fa, int gg) {
  gg = gcd(gg, A[x]);
  now[gg]++;
  for (int v : edge[x]) {
    if (v == fa || mark[v]) continue;
    dfs2(v, x, gg);
  }
}
unordered_map<long long, int> MMP;
inline int getgcd(int x, int y) {
  if (MMP[(long long)x * 1000000 + y])
    return MMP[(long long)x * 1000000 + y];
  else
    return MMP[(long long)x * 1000000 + y] = gcd(x, y);
}
void calc(int x) {
  MP.clear();
  MP[A[x]]++;
  for (int u : edge[x]) {
    if (mark[u]) continue;
    now.clear();
    dfs2(u, x, A[x]);
    for (auto P : now)
      for (auto Q : MP)
        ans[getgcd(P.first, Q.first)] += (long long)Q.second * P.second;
    for (auto P : now) MP[P.first] += P.second;
  }
  MP.clear();
}
void dfs3(int x) {
  calc(x);
  mark[x] = 1;
  ans[A[x]]++;
  for (int v : edge[x]) {
    if (mark[v]) continue;
    minweight = sz[v];
    dfs1(v, 0, sz[v]);
    dfs3(root);
  }
}
vector<pair<int, long long> > Ans;
int main() {
  int i, j, n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  minweight = n;
  dfs1(1, 0, n);
  dfs3(root);
  for (auto now : ans) Ans.push_back(now);
  sort(Ans.begin(), Ans.end());
  for (auto now : Ans) printf("%d %I64d\n", now.first, now.second);
}
