#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long double pi = 3.141592653589793238462643383279;
const long double log23 = 1.58496250072115618145373894394781;
const long double eps = 1e-11;
const long long INF = 1e18 + 239;
const long long prost = 239;
const int two = 2;
const int th = 3;
const long long MOD = 1e9 + 7;
const long long MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;
template <typename T>
inline T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <typename T>
inline T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
long long power(long long a, int k) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = (ans * a) % MOD;
    ans = (ans * ans) % MOD;
    k >>= 1;
  }
  return ans;
}
mt19937 rnd(239);
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 1e6 + 239;
bool can[M], used[M];
int n, a[M];
vector<int> ids[M];
vector<int> v[M];
long long ans[M], sz;
inline void dfs(int p) {
  used[p] = true;
  sz++;
  for (int i : v[p])
    if (can[i] && !used[i]) dfs(i);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) ids[a[i]].push_back(i);
  for (int i = 0; i < n - 1; i++) {
    int s, f;
    cin >> s >> f;
    s--, f--;
    v[s].push_back(f);
    v[f].push_back(s);
  }
  memset(can, 0, sizeof(can));
  memset(used, 0, sizeof(used));
  for (int i = 1; i < M; i++) {
    vector<int> now;
    for (int x = i; x < M; x += i)
      for (int t : ids[x]) now.push_back(t);
    for (int t : now) can[t] = true;
    ans[i] = 0;
    for (int t : now)
      if (!used[t]) {
        sz = 0;
        dfs(t);
        ans[i] += (sz * (sz + 1)) / 2LL;
      }
    for (int t : now) can[t] = false;
    for (int t : now) used[t] = false;
  }
  for (int i = M - 1; i >= 1; i--)
    for (int x = 2 * i; x < M; x += i) ans[i] -= ans[x];
  for (int i = 1; i < M; i++)
    if (ans[i] != 0) cout << i << " " << ans[i] << "\n";
  return 0;
}
