#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int mod = 1000000007;
int n, v[maxn], h, firs[maxn], x, y, p[maxn], mu[maxn], phi[maxn], vis[maxn],
    p_cnt, pri[maxn], F[maxn];
int siz[maxn], son[maxn], Top[maxn], f[maxn], ans, dep[maxn], inv_phi[maxn],
    a[maxn], m, id[maxn], id_cnt;
long long dp[maxn], sta[maxn], vv[maxn], va[maxn];
struct edge {
  int too, nex, c;
};
struct gragh {
  edge g[maxn << 1];
  int h, firs[maxn];
  void add(int x, int y, int c) {
    g[++h].nex = firs[x];
    firs[x] = h;
    g[h].too = y;
    g[h].c = c;
    g[++h].nex = firs[y];
    firs[y] = h;
    g[h].too = x;
    g[h].c = c;
  }
} g1, g;
int qui(int a, int b) {
  int s = 1;
  while (b) {
    if (b & 1) s = 1LL * s * a % mod;
    a = 1LL * a * a % mod;
    b >>= 1;
  }
  return s;
}
bool cmp(int a, int b) { return id[a] < id[b]; }
void init() {
  mu[1] = 1;
  phi[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!vis[i]) mu[i] = -1, phi[i] = i - 1, pri[++p_cnt] = i;
    for (int j = 1; j <= p_cnt && i * pri[j] <= n; ++j) {
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) {
        phi[i * pri[j]] = phi[i] * pri[j];
        break;
      }
      phi[i * pri[j]] = phi[i] * phi[pri[j]];
      mu[i * pri[j]] = -mu[i];
    }
  }
  for (int i = 1; i <= n; ++i) inv_phi[i] = qui(phi[i], mod - 2);
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; j += i)
      F[j] = (F[j] + 1LL * i * inv_phi[i] * mu[j / i] % mod + mod) % mod;
}
void dfs1(int x) {
  int j, maxs = -1;
  siz[x] = 1;
  for (int i = g1.firs[x]; i; i = g1.g[i].nex) {
    j = g1.g[i].too;
    if (dep[j]) continue;
    dep[j] = dep[x] + 1;
    f[j] = x;
    dfs1(j);
    siz[x] += siz[j];
    if (siz[j] >= maxs) maxs = siz[j], son[x] = j;
  }
}
void dfs2(int x, int Tp) {
  Top[x] = Tp;
  id[x] = ++id_cnt;
  if (!son[x]) return;
  dfs2(son[x], Tp);
  int j;
  for (int i = g1.firs[x]; i; i = g1.g[i].nex) {
    j = g1.g[i].too;
    if (j == f[x] || j == son[x]) continue;
    dfs2(j, j);
  }
}
int lca(int x, int y) {
  while (Top[x] != Top[y]) {
    if (dep[Top[x]] > dep[Top[y]]) swap(x, y);
    y = f[Top[y]];
  }
  return (dep[x] < dep[y]) ? x : y;
}
int d(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
void DP(int x) {
  int j, vl, t1 = 0, t2 = 0, len;
  dp[x] = 0;
  va[x] = 0;
  vv[x] = vl = vis[x] ? v[x] : 0;
  for (int i = g.firs[x]; i; i = g.g[i].nex) {
    j = g.g[i].too;
    if (dep[j] < dep[x]) continue;
    DP(j);
    len = g.g[i].c;
    dp[x] = (dp[x] + dp[j]) % mod;
    dp[x] = (dp[x] + 1LL * vl * (vv[j] * len % mod + va[j])) % mod;
    dp[x] =
        (dp[x] + 1LL * t2 * vv[j] + 1LL * t1 * (vv[j] * len % mod + va[j])) %
        mod;
    vv[x] = (vv[x] + vv[j]) % mod;
    va[x] = (va[x] + va[j] + vv[j] * len % mod) % mod;
    t1 = (t1 + vv[j]) % mod;
    t2 = (t2 + va[j] + vv[j] * len % mod) % mod;
  }
}
int ask(int x) {
  int m = 0, Tp = 0;
  for (int i = 1; i <= n / x; i++) a[++m] = p[i * x];
  g.h = 0;
  sort(a + 1, a + 1 + m, cmp);
  g.firs[1] = 0;
  for (int i = 1; i <= m; ++i) g.firs[a[i]] = 0, vis[a[i]] = 1;
  for (int i = 2; i <= m; ++i) g.firs[lca(a[i], a[i - 1])] = 0;
  sta[++Tp] = 1;
  int st = 1;
  if (a[1] == 1) st = 2;
  for (int i = st; i <= m; ++i) {
    int LCA = lca(sta[Tp], a[i]);
    while (Tp > 1 && LCA != sta[Tp]) {
      if (sta[Tp - 1] == LCA) {
        g.add(sta[Tp], sta[Tp - 1], dep[sta[Tp]] - dep[sta[Tp - 1]]);
        Tp--;
        break;
      }
      if (id[sta[Tp - 1]] < id[LCA]) {
        g.add(LCA, sta[Tp], dep[sta[Tp]] - dep[LCA]);
        sta[Tp] = LCA;
        break;
      }
      g.add(sta[Tp], sta[Tp - 1], dep[sta[Tp]] - dep[sta[Tp - 1]]);
      Tp--;
    }
    sta[++Tp] = a[i];
  }
  while (Tp > 1)
    g.add(sta[Tp], sta[Tp - 1], dep[sta[Tp]] - dep[sta[Tp - 1]]), Tp--;
  DP(1);
  for (int i = 1; i <= m; ++i) vis[a[i]] = 0;
  return dp[1] * 2 % mod;
}
inline int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x;
}
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; ++i) v[i] = read(), p[v[i]] = i, v[i] = phi[v[i]];
  for (int i = 1; i < n; ++i) {
    x = read(), y = read();
    g1.add(x, y, 1);
  }
  dep[1] = 1;
  dfs1(1);
  dfs2(1, 1);
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; ++i) ans = (ans + 1LL * F[i] * ask(i) % mod) % mod;
  ans = 1LL * ans * qui(1LL * n * (n - 1) % mod, mod - 2) % mod;
  printf("%d\n", ans);
  return 0;
}
