#include <bits/stdc++.h>
using namespace std;
map<int, long long> c[200018];
vector<int> a[200018];
int n, u, v, val[200018];
long long cnt[200018];
map<int, long long>::iterator it1, it2;
inline int read() {
  int X = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    X = (X << 3) + (X << 1) + ch - '0', ch = getchar();
  return X * w;
}
int gcd(int x, int y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
void dfs(int x, int fa) {
  c[x][val[x]]++;
  for (int i = (int)a[x].size() - 1; i >= 0; i--) {
    if (a[x][i] == fa) {
      continue;
    }
    int u = a[x][i];
    dfs(u, x);
    for (it1 = c[x].begin(); it1 != c[x].end(); it1++) {
      for (it2 = c[u].begin(); it2 != c[u].end(); it2++) {
        cnt[gcd(it1->first, it2->first)] += it1->second * it2->second;
      }
    }
    for (it1 = c[u].begin(); it1 != c[u].end(); it1++) {
      c[x][gcd(val[x], it1->first)] += it1->second;
    }
    c[u].clear();
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    val[i] = read();
    cnt[val[i]]++;
  }
  for (int i = 1; i < n; i++) {
    v = read(), u = read();
    a[u].push_back(v);
    a[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i <= 200000; i++) {
    if (cnt[i]) {
      printf("%d %lld\n", i, cnt[i]);
    }
  }
  return 0;
}
