#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
const double PI = acos(-1.0);
const double EPS = 1e-9;
const long long INF = 1e9;
const long long LINF = 1e18;
const long long mod = 1e9 + 7;
const long long MAX = 2e5 + 7;
int n;
int a[MAX];
vector<int> g[MAX];
long long DP[MAX];
vector<int> vert[MAX];
bool ye[MAX];
bool pozn[MAX];
int marked[MAX];
int counter = 0;
int q[MAX];
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &a[i]);
    vert[a[i]].push_back(i);
  }
  int u, v;
  for (int i = (0); i < (n - 1); ++i) {
    scanf("%d %d", &u, &v);
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = (1); i < (MAX); ++i) {
    counter = 0;
    for (int j = i; j < MAX; j += i) {
      int k;
      for (int to = (0); to < ((int)((vert[j]).size())); ++to) {
        k = vert[j][to];
        marked[counter++] = k;
        ye[k] = 1;
        pozn[k] = 0;
      }
    }
    long long tut = 0;
    for (int to = (0); to < (counter); ++to) {
      int k = marked[to];
      if (pozn[k]) continue;
      int poch = 0, kinec = 0;
      q[0] = k;
      pozn[k] = 1;
      int ye1 = 1;
      while (poch <= kinec) {
        int t = q[poch++];
        for (int to = (0); to < ((int)((g[t]).size())); ++to) {
          int su = g[t][to];
          if (pozn[su] || ye[su] == 0) continue;
          pozn[su] = 1;
          ++ye1;
          q[++kinec] = su;
        }
      }
      tut += ye1 * 1LL * (ye1 - 1) / 2LL;
    }
    DP[i] = tut;
    for (int k = (0); k < (counter); ++k) ye[marked[k]] = 0;
  }
  for (int i = (MAX)-1; i >= (1); --i)
    for (int j = i * 2; j < MAX; j += i) DP[i] -= DP[j];
  for (int i = (1); i < (MAX); ++i) DP[i] += (int)((vert[i]).size());
  for (int i = (1); i < (MAX); ++i)
    if (DP[i]) {
      printf("%d ", i);
      printf("%lld\n", DP[i]);
    }
  return 0;
}
