#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int ans, cnt, tot, top, n, w[N], f[N][20], mu[N], dep[N], phi[N], st[N],
    mark[N], a[N], b[N], p[N], dfn[N], dp[N][3];
vector<int> vis, s[N], e[N];
bool cmp(int x, int y) { return dfn[x] < dfn[y]; }
int qpow(int x, int y, int z) {
  int sum = 1;
  while (y) {
    if (y & 1) sum = 1ll * sum * x % z;
    y >>= 1;
    x = 1ll * x * x % z;
  }
  return sum;
}
void init() {
  phi[1] = mu[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!mark[i]) {
      p[++cnt] = i;
      phi[i] = i - 1;
      mu[i] = -1;
    }
    for (int j = 1; j <= cnt; j++) {
      if (i * p[j] > n) break;
      mark[i * p[j]] = 1;
      if (i % p[j] == 0) {
        phi[i * p[j]] = phi[i] * p[j];
        break;
      }
      phi[i * p[j]] = phi[i] * phi[p[j]];
      mu[i * p[j]] = -mu[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    int inv = qpow(phi[i], mod - 2, mod);
    for (int j = i; j <= n; j += i)
      (w[j] += 1ll * mu[j / i] * i * inv % mod) %= mod;
  }
}
void dfs1(int x, int fa) {
  dfn[x] = ++tot;
  dep[x] = dep[fa] + 1;
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y == fa) continue;
    f[y][0] = x;
    for (int j = 1; j < 20; j++) f[y][j] = f[f[y][j - 1]][j - 1];
    dfs1(y, x);
  }
}
void add(int x, int y) {
  vis.push_back(x);
  vis.push_back(y);
  s[x].push_back(y);
}
void dfs2(int x) {
  dp[x][0] = b[x];
  dp[x][1] = 0;
  dp[x][2] = 0;
  for (int i = 0; i < s[x].size(); i++) {
    int y = s[x][i];
    dfs2(y);
    (dp[x][2] += dp[y][2]) %= mod;
    (dp[x][2] +=
     (1ll * dp[x][0] * (1ll * dp[y][0] * (dep[y] - dep[x]) % mod + dp[y][1]) +
      1ll * dp[x][1] * dp[y][0]) %
     mod) %= mod;
    (dp[x][0] += dp[y][0]) %= mod;
    (dp[x][1] += (1ll * dp[y][0] * (dep[y] - dep[x]) % mod + dp[y][1]) % mod) %=
        mod;
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i > -1; i--)
    if (dep[f[x][i]] >= dep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 19; i > -1; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
int calc(int x) {
  vis.clear();
  vector<int> v;
  for (int i = x; i <= n; i += x) v.push_back(p[i]);
  sort(v.begin(), v.end(), cmp);
  st[top = 1] = v[0];
  vis.push_back(v[0]);
  for (int i = 1; i < v.size(); i++) {
    int k = st[top], l = lca(st[top], v[i]);
    if (l == k) {
      st[++top] = v[i];
      continue;
    }
    while (1) {
      k = st[top], l = lca(st[top], v[i]);
      int r = st[top - 1];
      if (dep[l] > dep[r]) {
        add(l, k);
        st[top] = l;
        st[++top] = v[i];
        break;
      } else if (dep[l] == dep[r]) {
        add(l, k);
        st[top] = v[i];
        break;
      } else {
        add(r, k);
        top--;
      }
    }
  }
  for (int i = 2; i <= top; i++) add(st[i - 1], st[i]);
  int root = v[0];
  for (int i = 0; i < vis.size(); i++) {
    if (dfn[vis[i]] < dfn[root]) root = vis[i];
    if (a[vis[i]] % x == 0)
      b[vis[i]] = phi[a[vis[i]]];
    else
      b[vis[i]] = 0;
  }
  dfs2(root);
  for (int i = 0; i < vis.size(); i++) s[vis[i]].clear();
  return dp[root][2];
}
signed main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), p[a[i]] = i;
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs1(1, 0);
  for (int i = 1; i <= n; i++) (ans += 1ll * w[i] * calc(i) % mod) %= mod;
  ans = 2ll * ans * qpow(1ll * n * (n - 1) % mod, mod - 2, mod) % mod;
  printf("%d\n", (ans + mod) % mod);
  return 0;
}
