#include <bits/stdc++.h>
using namespace std;
int wei[200005];
vector<int> v[200005];
vector<int> fact[200005];
bool per[200005];
int maxdis;
int dfs(int now, int father) {
  per[now] = 0;
  int max_child = 1;
  for (auto i : v[now]) {
    if (i != father) {
      if (per[i]) {
        int val = dfs(i, now);
        maxdis = max(maxdis, max_child + val);
        max_child = max(max_child, val + 1);
      }
    }
  }
  maxdis = max(maxdis, 1);
  return max_child;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> wei[i];
    for (int j = 2; j * j <= wei[i]; j++) {
      if (wei[i] % j == 0) {
        fact[j].push_back(i);
        if (wei[i] / j != j) {
          fact[wei[i] / j].push_back(i);
        }
      }
    }
    fact[wei[i]].push_back(i);
  }
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--, b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 2; i < 200005; i++) {
    for (auto j : fact[i]) {
      per[j] = 1;
    }
    for (auto j : fact[i]) dfs(j, -1);
  }
  cout << maxdis << endl;
}
