#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 13;
long long dp[MAXN];
int odw[MAXN];
int war[MAXN];
vector<int> v[MAXN];
vector<int> val[MAXN];
int DFS(int x, int licz) {
  odw[x] = licz;
  int roz = 1;
  for (auto it : v[x]) {
    if (odw[it] != licz && war[it] % licz == 0) roz += DFS(it, licz);
  }
  return roz;
}
int main() {
  int n;
  int x, y;
  long long a;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    war[i] = x;
    for (int j = 1; j * j < x; j++) {
      if (x % j == 0) {
        val[j].emplace_back(i);
        val[x / j].emplace_back(i);
      }
    }
    y = sqrt(x);
    if (y * y == x) val[y].emplace_back(i);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    v[x].emplace_back(y);
    v[y].emplace_back(x);
  }
  for (int i = 1; i < MAXN; i++) {
    for (auto it : val[i]) {
      if (odw[it] != i) {
        a = DFS(it, i);
        dp[i] += a * (a + 1) / 2;
      }
    }
  }
  for (int i = MAXN / 2 - 1; i > 0; i--) {
    for (int j = i * 2; j < MAXN; j += i) dp[i] -= dp[j];
  }
  for (int i = 1; i < MAXN; i++) {
    if (dp[i] != 0) printf("%d %lld\n", i, dp[i]);
  }
  return 0;
}
