#include <bits/stdc++.h>
using namespace std;
vector<int> d[200005 + 10], g[200005 + 10];
int dist, M[200005 + 10], MP[200005 + 10], x, y, val;
void dfs(int x, int m, int dis, int z) {
  M[x] = m;
  if (dis > dist) {
    dist = dis;
    val = x;
  }
  for (auto i : g[x]) {
    if (M[i] == m || MP[i] != z) continue;
    dfs(i, m, dis + 1, z);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (unsigned long long i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 1; j * j <= x; j++) {
      if (x % j == 0) {
        d[j].push_back(i + 1);
        if (j * j != x) d[x / j].push_back(i + 1);
      }
    }
  }
  for (unsigned long long i = 1; i < n; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 2; i < 200005 - 1; i++) {
    if (ans >= d[i].size()) continue;
    for (auto it : d[i]) MP[it] = i;
    for (auto it : d[i]) {
      dist = 0;
      val = 0;
      if (M[it] == 2) continue;
      dfs(it, 1, 1, i);
      dfs(val, 2, 1, i);
      ans = max(ans, dist);
    }
  }
  cout << ans << endl;
  return 0;
}
