#include <bits/stdc++.h>
using namespace std;
int vr[500006] = {0};
vector<int> vn[200005 + 1];
int arr[200005 + 1] = {0}, an = 0;
vector<pair<int, int> > pr;
int dfs(int s, int prm) {
  vr[s] = 1;
  int temp = 0, tm1 = 0, tm2 = 0;
  for (int i = 0; i < vn[s].size(); ++i)
    if (vr[vn[s][i]] == 0 && arr[vn[s][i]] % prm == 0) {
      int t2 = dfs(vn[s][i], prm);
      if (temp == 0)
        tm1 = max(tm1, t2);
      else {
        if (tm1 < t2) {
          tm2 = tm1;
          tm1 = t2;
        } else if (tm2 < t2)
          tm2 = t2;
      }
      temp = 1;
    }
  an = max(an, tm1 + tm2 + 1);
  return tm1 + 1;
}
int prr[200009] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int r = 0, ans = 0, n = 1, fu = 0;
  cin >> n;
  memset(prr, 0, sizeof(prr));
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
    r = max(r, arr[i]);
    fu = arr[i];
    for (int j = 2; j * j <= arr[i]; j++)
      if (arr[i] % j == 0) {
        prr[j]++;
        while (arr[i] % j == 0) arr[i] /= j;
      }
    if (arr[i] > 1) prr[arr[i]]++;
    arr[i] = fu;
  }
  for (int i = 2; i <= r; i++)
    if (prr[i] > 0) pr.push_back(make_pair(prr[i], i));
  sort(pr.rbegin(), pr.rend());
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    vn[u].push_back(v);
    vn[v].push_back(u);
  }
  for (int i = 0; i < pr.size() && pr[i].first > an; i++) {
    int nm = pr[i].second;
    for (int k = 1; k <= n; ++k) {
      if (vr[k] == 0 && arr[k] % nm == 0) {
        int yy = dfs(k, nm);
        pr[i].first -= yy;
      }
      if (pr[i].first <= an) break;
    }
    memset(vr, 0, sizeof(vr));
  }
  cout << an;
}
