#include <bits/stdc++.h>
using namespace std;
const int N = 200005, mod = 1e9 + 7;
int n, cnt, prime[N], phi[N], mu[N], a[N], id[N], c[N];
bool vis[N];
int Pow(int x, int k) {
  int ret = 1;
  while (k) {
    if (k & 1) ret = (long long)ret * x % mod;
    k >>= 1;
    x = (long long)x * x % mod;
  }
  return ret;
}
void init() {
  mu[1] = phi[1] = 1;
  for (int i = 2; i <= 200000; i++) {
    if (!vis[i]) {
      prime[++prime[0]] = i;
      mu[i] = -1;
      phi[i] = i - 1;
    }
    for (int j = 1; j <= prime[0] && i * prime[j] <= 200000; j++) {
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        phi[i * prime[j]] = phi[i] * prime[j];
        break;
      }
      mu[i * prime[j]] = -mu[i];
      phi[i * prime[j]] = phi[i] * (prime[j] - 1);
    }
  }
}
int h[N], dep[N], re[N * 2], fir[N * 2], bin[N * 2], p[N * 2][22];
bool mark[N];
int q[N], st[N], tot, top, dfn[N], sign;
int f[N], g[N], size[N];
struct edge {
  int to, next, w;
} e[N * 2];
void addedge(int x, int y, int z) {
  e[++cnt] = (edge){y, h[x], z};
  h[x] = cnt;
}
void dfs(int x, int fa) {
  dep[x] = dep[fa] + 1;
  dfn[x] = ++dfn[0];
  re[++sign] = x;
  fir[x] = sign;
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (y == fa) continue;
    dfs(y, x);
    re[++sign] = x;
  }
}
bool cmp(int x, int y) { return dfn[x] < dfn[y]; }
int lca(int x, int y) {
  x = fir[x];
  y = fir[y];
  if (x > y) swap(x, y);
  int k = bin[y - x + 1];
  return dep[p[x][k]] < dep[p[y - (1 << k) + 1][k]] ? p[x][k]
                                                    : p[y - (1 << k) + 1][k];
}
void dp(int x) {
  size[x] = f[x] = g[x] = 0;
  if (mark[x]) size[x] = phi[a[x]];
  for (int &i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    dp(y);
    f[x] =
        (f[x] + f[y] + (long long)size[x] * g[y] + (long long)size[y] * g[x] +
         (long long)size[x] * size[y] % mod * e[i].w) %
        mod;
    g[x] = (g[x] + g[y] + (long long)size[y] * e[i].w) % mod;
    size[x] = (size[x] + size[y]) % mod;
  }
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int tmp = (long long)i * Pow(phi[i], mod - 2) % mod;
    for (int j = 1; i * j <= n; j++)
      c[i * j] = (c[i * j] + (long long)mu[j] * tmp) % mod;
  }
  bin[1] = 0;
  for (int i = 2; i <= 2 * n; i++) bin[i] = bin[i >> 1] + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    id[a[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addedge(x, y, 1);
    addedge(y, x, 1);
  }
  dfs(1, 0);
  for (int i = 1; i <= sign; i++) p[i][0] = re[i];
  for (int j = 1; (1 << j) <= sign; j++) {
    for (int i = 1; i + (1 << j) - 1 <= sign; i++)
      p[i][j] = dep[p[i][j - 1]] < dep[p[i + (1 << j - 1)][j - 1]]
                    ? p[i][j - 1]
                    : p[i + (1 << j - 1)][j - 1];
  }
  memset(h, 0, sizeof(h));
  cnt = 0;
  int ans = 0;
  for (int T = 1; T <= n; T++) {
    tot = top = cnt = 0;
    for (int i = T; i <= n; i += T) {
      q[++tot] = id[i];
      mark[id[i]] = 1;
    }
    sort(q + 1, q + tot + 1, cmp);
    if (q[1] != 1) st[++top] = 1;
    for (int i = 1; i <= tot; i++) {
      int now = q[i], f = 0;
      while (top > 0) {
        f = lca(st[top], now);
        if (top > 1 && dep[f] < dep[st[top - 1]]) {
          addedge(st[top - 1], st[top], dep[st[top]] - dep[st[top - 1]]);
          top--;
        } else if (dep[f] < dep[st[top]]) {
          addedge(f, st[top], dep[st[top]] - dep[f]);
          top--;
          break;
        } else
          break;
      }
      if (st[top] != f) st[++top] = f;
      st[++top] = now;
    }
    while (top > 1)
      addedge(st[top - 1], st[top], dep[st[top]] - dep[st[top - 1]]), top--;
    dp(1);
    for (int i = 1; i <= tot; i++) mark[q[i]] = 0;
    ans = (ans + (long long)f[1] * c[T]) % mod;
  }
  cout << ((long long)ans * Pow((long long)n * (n - 1) / 2 % mod, mod - 2) %
               mod +
           mod) %
              mod
       << "\n";
}
