#include <bits/stdc++.h>
using namespace std;
int n;
int fun(vector<vector<int> > &al) {
  int i, j, ans = 1;
  vector<int> visited(n + 1, 0), visited1(n + 1, 0);
  for (i = 1; i <= n; i++) {
    if (!visited[i]) {
      int md = 1, mn = i;
      queue<int> q;
      q.push(i);
      visited[i] = 1;
      while (!q.empty()) {
        int t = q.front();
        q.pop();
        for (j = 0; j < al[t].size(); j++) {
          if (!visited[al[t][j]]) {
            q.push(al[t][j]);
            visited[al[t][j]] = 1;
            mn = al[t][j];
          }
        }
      }
      queue<int> q1;
      q1.push(mn);
      visited1[mn] = 1;
      while (!q1.empty()) {
        int t = q1.front();
        q1.pop();
        for (j = 0; j < al[t].size(); j++) {
          if (!visited1[al[t][j]]) {
            q1.push(al[t][j]);
            visited1[al[t][j]] = visited1[t] + 1;
            md = visited1[t] + 1;
          }
        }
      }
      ans = max(md, ans);
    }
  }
  return ans;
}
int check(vector<int> &arr) {
  int i;
  for (i = 1; i <= n; i++)
    if (arr[i] > 1) return 0;
  return 1;
}
int main() {
  cin >> n;
  int i, j, ans = 1, pi = 0;
  vector<int> arr(n + 1);
  vector<vector<int> > pa(200005);
  vector<int> pv, pia(200005);
  for (i = 2; i <= 200000; i++) {
    if (pa[i].empty()) {
      pv.push_back(i);
      pia[i] = pi;
      pi++;
      for (j = i; j <= 200000; j += i) pa[j].push_back(i);
    }
  }
  for (i = 1; i <= n; i++) scanf("%d", &arr[i]);
  if (check(arr)) {
    cout << 0;
    return 0;
  }
  vector<int> utila(pv.size());
  vector<pair<int, int> > ev;
  for (i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    ev.push_back({u, v});
    for (j = 0; j < pa[arr[u]].size(); j++) {
      int pno = pa[arr[u]][j];
      if (arr[v] % pno == 0) utila[pia[pno]]++;
    }
  }
  vector<pair<int, int> > xvec;
  for (i = 0; i < pv.size(); i++) xvec.push_back({utila[i], pv[i]});
  sort(xvec.begin(), xvec.end());
  int x = 0;
  for (i = xvec.size() - 1; i >= xvec.size() - 500; i--) {
    vector<vector<int> > al(n + 1);
    if (xvec[i].first >= ans) {
      for (j = 0; j < n - 1; j++) {
        if (arr[ev[j].first] % xvec[i].second == 0 &&
            arr[ev[j].second] % xvec[i].second == 0) {
          al[ev[j].first].push_back(ev[j].second);
          al[ev[j].second].push_back(ev[j].first);
        }
      }
      x++;
      ans = max(ans, fun(al));
    }
  }
  cout << ans;
  return 0;
}
