#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smax(T &a, const U &b) {
  if (a < b) a = b;
}
int a[200200];
int f[200200];
vector<int> adj[200200], vec[200200];
int vst[200200], runs;
int flag[200200], ans;
int dfs(int u) {
  vst[u] = runs;
  int one = 0, two = 0;
  for (int i = adj[u].size(); i--;) {
    int v = adj[u][i];
    if (flag[v] == runs && vst[v] != runs) {
      int mx = dfs(v);
      if (mx > two) {
        two = mx;
        if (one < two) swap(one, two);
      }
    }
  }
  smax(ans, one + two + 1);
  return one + 1;
}
int main() {
  for (int i = 2; i <= 200000; i++)
    if (!f[i]) {
      f[i] = i;
      if ((long long)i * i >= 200200) continue;
      for (int j = i * i; j <= 200000; j += i) f[j] = i;
    }
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    int u = a[i];
    while (u > 1) {
      int first = f[u];
      while (u > 1 && u % first == 0) u /= first;
      vec[first].push_back(i);
    }
  }
  for (int I = 2; I <= 200000; I++)
    if (!vec[I].empty()) {
      runs++;
      for (int i = vec[I].size(); i--;) {
        int u = vec[I][i];
        flag[u] = runs;
      }
      for (int i = vec[I].size(); i--;) {
        int u = vec[I][i];
        if (vst[u] != runs) dfs(u);
      }
    }
  cout << ans << endl;
}
