#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
map<int, int> mp[maxn][2];
vector<int> G[maxn];
vector<int> fac[maxn];
int ans = 1;
void get_fac(int x, int id) {
  int n = x;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      fac[id].push_back(i);
    }
  }
  if (n != 1) fac[id].push_back(n);
}
void dfs(int u, int fa) {
  for (int i = 0; i < fac[u].size(); i++) mp[u][0][fac[u][i]] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int to = G[u][i];
    if (to == fa) continue;
    dfs(to, u);
    for (int j = 0; j < fac[u].size(); j++) {
      int nxt = fac[u][j];
      int Max = mp[to][0][nxt];
      if (Max + 1 > mp[u][0][nxt]) {
        mp[u][1][nxt] = mp[u][0][nxt];
        mp[u][0][nxt] = Max + 1;
      } else if (Max + 1 == mp[u][0][nxt])
        mp[u][1][nxt] = Max + 1;
      else if (Max + 1 > mp[u][1][nxt])
        mp[u][1][nxt] = Max + 1;
      ans = max(ans, mp[u][0][nxt] + mp[u][1][nxt] - 1);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (x != 1) flag = 0;
    get_fac(x, i);
  }
  if (flag) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
