#include <bits/stdc++.h>
using namespace std;
int read();
const int N = 200005, P = 1000000007;
int n;
int a[N], b[N], pri[N], pc, mu[N], phi[N];
bool mk[N];
vector<int> TO[N], to[N];
int fr[N], eu[20][N << 1], EU, lg[N << 1], fa[N], dep[N], p[N], sta[N], top;
int mo(int x) { return x >= P ? x - P : x; }
int qpow(int x, int b, int res = 1) {
  for (; b; b >>= 1, x = 1ll * x * x % P)
    if (b & 1) res = 1ll * res * x % P;
  return res;
}
int f[N], g[N], s[N], res;
void dfs1(int u) {
  eu[0][fr[u] = ++EU] = u;
  for (int v : TO[u])
    if (v != fa[u]) {
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs1(v);
      eu[0][++EU] = u;
    }
}
void dfs2(int u, int fa) {
  s[u] = 0;
  for (int v : to[u])
    if (v != fa) {
      dfs2(v, u);
      res = (res + 2ll * s[u] * s[v] % P * dep[u]) % P;
      s[u] = mo(s[u] + s[v]);
    }
  if (mk[u]) {
    res = (res + 2ll * phi[u] * s[u] % P * dep[u] % P +
           1ll * phi[u] * phi[u] % P * dep[u] % P) %
          P;
    s[u] = mo(s[u] + phi[u]);
  }
  to[u].clear();
}
int getlca(int l, int r) {
  l = fr[l], r = fr[r];
  if (l > r) swap(l, r);
  int k = lg[r - l + 1];
  return dep[eu[k][l]] < dep[eu[k][r - (1 << k) + 1]] ? eu[k][l]
                                                      : eu[k][r - (1 << k) + 1];
}
void link(int x, int y) {
  to[x].push_back(y);
  to[y].push_back(x);
}
bool cmp(int x, int y) { return fr[x] < fr[y]; }
int main() {
  n = read();
  for (int(i) = (1); (i) <= (n); ++(i)) b[a[i] = read()] = i;
  for (int i = 1, x, y; i < n; ++i) {
    x = a[read()], y = a[read()];
    TO[x].push_back(y);
    TO[y].push_back(x);
  }
  dep[1] = 1;
  dfs1(1);
  for (int(i) = (2); (i) <= (EU); ++(i)) lg[i] = lg[i >> 1] + 1;
  for (int j = 1; (1 << j) <= EU; ++j)
    for (int i = 1; i + (1 << j) - 1 <= EU; ++i)
      eu[j][i] = dep[eu[j - 1][i]] < dep[eu[j - 1][i + (1 << j - 1)]]
                     ? eu[j - 1][i]
                     : eu[j - 1][i + (1 << j - 1)];
  phi[1] = mu[1] = 1;
  for (int(i) = (2); (i) <= (n); ++(i)) {
    if (!mk[i]) pri[++pc] = i, mu[i] = -1, phi[i] = i - 1;
    for (int j = 1; j <= pc && i * pri[j] <= n; ++j) {
      mk[i * pri[j]] = 1;
      if (i % pri[j])
        mu[i * pri[j]] = -mu[i], phi[i * pri[j]] = phi[i] * (pri[j] - 1);
      else {
        phi[i * pri[j]] = phi[i] * pri[j];
        break;
      }
    }
  }
  memset(mk, 0, sizeof mk);
  for (int(x) = (1); (x) <= (n); ++(x)) {
    if (x > n / 2) break;
    top = p[0] = 0;
    for (int i = x; i <= n; i += x) mk[p[++p[0]] = i] = 1;
    sort(p + 1, p + p[0] + 1, cmp);
    int sv = phi[p[1]], svd = 1ll * phi[p[1]] * dep[p[1]] % P, st = p[1];
    sta[++top] = p[1];
    for (int o = 2, i; o <= p[0]; ++o) {
      i = p[o];
      sv = mo(sv + phi[i]);
      svd = (svd + 1ll * phi[i] * dep[i]) % P;
      int lca = getlca(i, sta[top]);
      if (dep[lca] < dep[st]) st = lca;
      while (1) {
        if (dep[lca] >= dep[sta[top - 1]]) {
          if (lca ^ sta[top]) {
            link(lca, sta[top]);
            if (lca ^ sta[top - 1])
              sta[top] = lca;
            else
              --top;
          }
          break;
        } else {
          link(sta[top - 1], sta[top]);
          --top;
        }
      }
      sta[++top] = i;
      if (dep[i] < dep[st]) st = i;
    }
    while (--top > 0) link(sta[top], sta[top + 1]);
    res = 0;
    dfs2(st, 0);
    g[x] = 2ll * (1ll * svd * sv % P - res + P) % P;
    g[x] = mo(g[x] + P);
    for (int i = x; i <= n; i += x) mk[i] = 0;
  }
  for (int x = 1; x <= n; f[x] = mo(f[x] + P), ++x)
    for (int d = x; d <= n; d += x) f[x] = (f[x] + 1ll * g[d] * mu[d / x]) % P;
  int ans = 0;
  for (int(d) = (1); (d) <= (n); ++(d))
    ans = (ans + 1ll * d * qpow(phi[d], P - 2) % P * f[d]) % P;
  ans = 1ll * qpow(1ll * n * (n - 1) % P, P - 2) * ans % P;
  printf("%d\n", ans);
  return 0;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f * x;
}
