#include <bits/stdc++.h>
using namespace std;
const long long int N = 200009;
long long int n, a[N], ls[N], t[N], kq = 0;
vector<long long int> D[N], uoc[N], maxx[N];
bool ok = 1;
void Inp() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != 1) {
      ok = 0;
    }
  }
  for (int i = 1; i < n; i++) {
    long long int u, v;
    cin >> u >> v;
    D[u].push_back(v);
    D[v].push_back(u);
  }
}
void Sieve() {
  ls[1] = 1;
  for (int i = 2; i < N; i++) {
    if (ls[i] == 0) {
      long long int k = i;
      while (k < N) {
        ls[k] = i;
        k += i;
      }
    }
  }
}
void Pre() {
  for (int i = 1; i <= n; i++) {
    long long int k = a[i];
    while (k > 1) {
      if (t[ls[k]] != i) {
        t[ls[k]] = i;
        uoc[i].push_back(ls[k]);
        maxx[i].push_back(0);
      }
      k /= ls[k];
    }
    sort(uoc[i].begin(), uoc[i].end());
  }
}
void DFS(long long int u, long long int p) {
  for (auto v : D[u]) {
    if (v != p) {
      DFS(v, u);
      long long int s1 = uoc[u].size(), s2 = uoc[v].size(), p1 = 0, p2 = 0;
      while (!(p1 == s1 || p2 == s2)) {
        if (uoc[u][p1] == uoc[v][p2]) {
          kq = max(kq, maxx[u][p1] + maxx[v][p2] + 1);
          maxx[u][p1] = max(maxx[u][p1], maxx[v][p2] + 1);
          p1++;
          p2++;
          continue;
        }
        if (uoc[u][p1] < uoc[v][p2]) {
          p1++;
        } else {
          p2++;
        }
      }
    }
  }
}
int main() {
  Inp();
  if (ok) {
    cout << 0;
    return 0;
  }
  Sieve();
  Pre();
  DFS(1, 1);
  cout << kq + 1;
}
