#include <bits/stdc++.h>
using namespace std;
const int N = 200035;
int cc = 0;
static int used[N];
static int a[N];
static int d[N];
vector<int> G[N];
vector<int> mdG[N];
vector<int> factors[N];
pair<int, int> BFS(int x, set<int>& dust) {
  cc++;
  used[x] = cc;
  queue<int> q;
  q.push(x);
  d[x] = 1;
  pair<int, int> ans = make_pair(x, d[x]);
  while (!q.empty()) {
    int k = q.front();
    ans = make_pair(k, d[k]);
    dust.insert(k);
    q.pop();
    for (auto it : mdG[k]) {
      if (used[it] != cc) {
        used[it] = cc;
        d[it] = d[k] + 1;
        q.push(it);
      }
    }
  }
  return ans;
}
int maximum = 0;
void result(int prime) {
  if (factors[prime].empty()) {
    return;
  } else {
    for (auto x : factors[prime]) {
      mdG[x].clear();
      for (auto y : G[x]) {
        if (a[y] % prime == 0) {
          mdG[x].push_back(y);
        }
      }
    }
    set<int> dust;
    for (auto x : factors[prime]) {
      if (!dust.count(x)) {
        pair<int, int> leaf1 = BFS(x, dust);
        pair<int, int> leaf2 = BFS(leaf1.first, dust);
        maximum = max(maximum, leaf2.second);
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int x = a[i];
    for (int j = 2; j * 1ll * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        factors[j].push_back(i);
        while (a[i] % j == 0) {
          a[i] /= j;
        }
      }
    }
    if (a[i] > 1) {
      factors[a[i]].push_back(i);
    }
    a[i] = x;
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 2; i <= 200000; i++) {
    result(i);
  }
  cout << maximum;
  return 0;
}
