#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
map<int, int> dp[maxn];
vector<int> fuck[maxn];
int a[maxn];
vector<int> factor[maxn];
int ans = 0;
bool cmp(int aa, int bb) { return aa > bb; }
void dfs(int u, int fa) {
  for (auto it : factor[a[u]]) {
    dp[u][it] = 1;
    ans = max(ans, 1);
  }
  for (auto v : fuck[u]) {
    if (v == fa) continue;
    dfs(v, u);
    for (auto it : factor[a[v]]) {
      if (dp[u][it]) {
        int tmp = dp[v][it];
        ans = max(ans, tmp + dp[u][it]);
        dp[u][it] = max(dp[u][it], dp[v][it] + 1);
      }
    }
    dp[v].clear();
  }
}
int main() {
  int i, j, k, n, m, t, l, r;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &j, &k);
    fuck[j].push_back(k);
    fuck[k].push_back(j);
  }
  for (i = 2; i < maxn; i++) {
    if (factor[i].empty())
      for (j = i; j < maxn; j += i) factor[j].push_back(i);
  }
  dfs(1, 0);
  printf("%d\n", ans);
}
