#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 96;
const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;
const int MAX_ASCII_CODE = 26;
const int MAX_NUMBER_OF_NODES = 1e5 + 5;
long long n, k;
vector<vector<int> > okinawa;
vector<vector<int> > adj;
int values[MAXN];
int primal[MAXN];
int diameter(vector<vector<int> >& adja, int no) {
  if (no == 0) return 0;
  vector<int> vis(no + 1, 0);
  queue<int> myq;
  queue<pair<int, int> > myq2;
  int ans = 1;
  for (int i = (int)1; i < (int)(no + 1); i++) {
    if (vis[i] == 0) {
      myq.push(i);
      vis[i]++;
      int start = i, end, temp;
      while (!myq.empty()) {
        start = myq.front();
        myq.pop();
        for (auto j : adja[start]) {
          if (vis[j] == 0) {
            myq.push(j);
            vis[j]++;
          }
        }
      }
      myq2.push({start, 1});
      vis[start]++;
      while (!myq2.empty()) {
        end = myq2.front().first;
        start = myq2.front().second;
        myq2.pop();
        for (auto j : adja[end]) {
          if (vis[j] == 1) {
            myq2.push({j, start + 1});
            vis[j]++;
          }
        }
      }
      ans = max(start, ans);
    }
  }
  return ans;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(NULL);
  cout << fixed << setprecision(10);
  int t;
  t = 1;
  while ((t--)) {
    cin >> n;
    int temp, temp2;
    adj.assign(MAXN, {});
    okinawa.assign(MAXN, {});
    for (int i = (int)0; i < (int)(n); i++) {
      cin >> temp;
      okinawa[temp].push_back(i + 1);
      values[i + 1] = temp;
    }
    for (int i = (int)1; i < (int)(n); i++) {
      cin >> temp >> temp2;
      adj[temp].push_back(temp2);
      adj[temp2].push_back(temp);
    }
    unordered_map<int, int> mymp;
    vector<int> nodes;
    vector<vector<int> > adj2;
    int ans = 0;
    for (int i = (int)2; i < (int)(MAXN); i++) {
      if (primal[i] == 0) {
        temp = 0;
        mymp.clear();
        nodes.assign(0, 0);
        for (auto to : okinawa[i]) {
          mymp[to] = ++temp;
          nodes.push_back(to);
        }
        for (int j = 2 * i; j < MAXN; j += i) {
          primal[j] = 1;
          for (auto to : okinawa[j]) {
            mymp[to] = ++temp;
            nodes.push_back(to);
          }
        }
        adj2.assign(temp + 1, {});
        for (int ho = (int)0; ho < (int)(nodes.size()); ho++) {
          for (auto to : adj[nodes[ho]])
            if (values[to] % i == 0) adj2[ho + 1].push_back(mymp[to]);
        }
        ans = max(ans, diameter(adj2, temp));
      }
    }
    cout << ans << "\n";
  }
}
