#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj(200001), vertices(200001);
bool marked[200001];
long long ans[200001];
int DFS(int i) {
  marked[i] = 0;
  int ans = 1;
  for (auto k : adj[i]) {
    if (marked[k]) {
      ans += DFS(k);
    }
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    vertices[x].push_back(i);
  }
  for (int x = 1; x < n; ++x) {
    int i, j;
    scanf("%d%d", &i, &j);
    adj[i].push_back(j);
    adj[j].push_back(i);
  }
  for (int i = 200001 - 1; i > 0; --i) {
    vector<int> v;
    for (int j = i; j < 200001; j += i) {
      for (auto x : vertices[j]) {
        v.push_back(x);
        marked[x] = 1;
      }
    }
    long long val = 0;
    for (auto x : v) {
      if (marked[x] == 0) continue;
      long long valx = DFS(x);
      val += (valx * (valx + 1) / 2);
    }
    ans[i] = val;
    for (int j = i + i; j < 200001; j += i) ans[i] -= ans[j];
  }
  for (int i = 1; i < 200001; ++i) {
    if (ans[i]) {
      printf("%d %lld\n", i, ans[i]);
    }
  }
  return 0;
}
