#include <bits/stdc++.h>
using namespace std;
int n, a[400005];
long long Ans[400005];
int TOT, LA[400005], NE[400005], EN[400005];
int Min, rt, sz[400005];
bool mark[400005];
void Link(int x, int y) {
  EN[++TOT] = y;
  NE[TOT] = LA[x];
  LA[x] = TOT;
  EN[++TOT] = x;
  NE[TOT] = LA[y];
  LA[y] = TOT;
}
void Gsi(int x, int f) {
  int i, y;
  sz[x] = 1;
  for (i = LA[x]; i; i = NE[i]) {
    y = EN[i];
    if (y == f || mark[y]) continue;
    Gsi(y, x);
    sz[x] += sz[y];
  }
}
void Grt(int x, int d, int f) {
  int i, y, Max = d - sz[x];
  for (i = LA[x]; i; i = NE[i]) {
    y = EN[i];
    if (y == f || mark[y]) continue;
    Grt(y, d, x);
    Max = max(Max, sz[y]);
  }
  if (Max < Min) Min = Max, rt = x;
}
map<int, int> Q;
map<int, int>::iterator it;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void getans(int x, int d, int f) {
  for (it = Q.begin(); it != Q.end(); ++it)
    Ans[gcd(it->first, d)] += it->second;
  for (int i = LA[x]; i; i = NE[i]) {
    int y = EN[i];
    if (y == f || mark[y]) continue;
    getans(y, gcd(d, a[y]), x);
  }
}
void modify(int x, int d, int f) {
  Q[d]++;
  for (int i = LA[x]; i; i = NE[i]) {
    int y = EN[i];
    if (y == f || mark[y]) continue;
    modify(y, gcd(d, a[y]), x);
  }
}
void Getans(int x) {
  int i, j, k, y;
  Q.clear();
  Q[a[x]] = 1;
  Ans[a[x]]++;
  for (i = LA[x]; i; i = NE[i]) {
    y = EN[i];
    if (mark[y]) continue;
    k = gcd(a[x], a[y]);
    getans(y, k, x);
    modify(y, k, x);
  }
}
void DC(int x) {
  mark[x] = 1;
  int i, y;
  Getans(x);
  for (i = LA[x]; i; i = NE[i]) {
    y = EN[i];
    if (mark[y]) continue;
    Min = 1e9;
    Gsi(y, x);
    Grt(y, sz[y], x);
    DC(rt);
  }
}
int main() {
  int i, j, k, x, y, z;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    Link(x, y);
  }
  Min = 1e9;
  Gsi(1, 0);
  Grt(1, n, 0);
  DC(rt);
  for (i = 1; i < 400005; i++)
    if (Ans[i]) printf("%d %I64d\n", i, Ans[i]);
}
