#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int a[MAXN];
vector<int> p[MAXN], g[MAXN];
int ans;
map<int, int> mp[MAXN];
void DFS(int u, int pre) {
  for (auto &x : p[a[u]]) mp[u][x] = 1;
  for (auto &v : g[u])
    if (v != pre) {
      DFS(v, u);
      for (auto &x : p[a[v]])
        if (a[u] % x == 0) {
          ans = max(ans, mp[u][x] + mp[v][x]);
          if (mp[v][x] + 1 > mp[u][x]) mp[u][x] = mp[v][x] + 1;
        }
    }
  return;
}
int main() {
  int n;
  for (int i = 2; i < MAXN; ++i)
    if (p[i].size() == 0)
      for (int j = i; j < MAXN; j += i) p[j].push_back(i);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), ans = max(ans, (a[i] > 1 ? 1 : 0));
  for (int i = 1, x, y; i < n; ++i)
    scanf("%d%d", &x, &y), g[x].push_back(y), g[y].push_back(x);
  DFS(1, 0);
  printf("%d\n", ans);
  return 0;
}
