#include <bits/stdc++.h>
using namespace std;
const int maxn = 2E5 + 5;
const long long int base = 2E5 + 5;
int n, val[maxn];
int head[maxn * 2], size;
long long int ans[maxn], wait[maxn];
bool vis[maxn];
inline int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); }
struct edge {
  int to, next;
} E[maxn * 2];
inline void add(int u, int v) {
  E[++size].to = v;
  E[size].next = head[u];
  head[u] = size;
}
struct note {
  int x, c;
  note(int a = 0, int b = 0) { x = a, c = b; }
};
queue<note> T[maxn];
vector<note> t;
void dfs(int u, int F) {
  vector<int> what;
  for (int i = head[u]; i; i = E[i].next) {
    int v = E[i].to;
    if (v == F) continue;
    dfs(v, u);
  }
  for (int i = head[u]; i; i = E[i].next) {
    int v = E[i].to;
    if (v == F) continue;
    t.clear();
    while (!T[v].empty()) {
      t.push_back(T[v].front());
      T[v].pop();
    }
    for (int j = 0; j < what.size(); ++j) {
      int x = what[j];
      for (int k = 0; k < t.size(); ++k)
        ans[gcd(x, t[k].x)] += wait[x] * t[k].c;
    }
    for (int j = 0; j < t.size(); ++j) {
      int x = gcd(val[u], t[j].x);
      if (!vis[x]) {
        vis[x] = 1;
        wait[x] = t[j].c;
        what.push_back(x);
      } else
        wait[x] += t[j].c;
    }
  }
  if (!vis[val[u]]) {
    vis[val[u]] = 1;
    wait[val[u]] = 1;
    what.push_back(val[u]);
  } else
    ++wait[val[u]];
  for (int i = 0; i < what.size(); ++i) {
    long long int x = what[i];
    ans[x] += wait[x];
    T[u].push(note(x, wait[x]));
    vis[x] = wait[x] = 0;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> val[i];
  for (int i = 1; i <= n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    add(x, y);
    add(y, x);
  }
  dfs(1, 1);
  for (int i = 1; i <= 200000; ++i)
    if (ans[i]) cout << i << " " << ans[i] << endl;
  return 0;
}
