#include <bits/stdc++.h>
using namespace std;
const int N = 201000, mod = 1e9 + 7;
int add(int x, int y) {
  x += y;
  while (x >= mod) x -= mod;
  return x;
}
int power(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (long long)ans * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ans;
}
struct Edge {
  int next, end;
} edge[N << 1];
vector<int> q[N], q2[N];
bool bo[N];
int pri[N], phi[N], mu[N], len, fx[N];
int dfn[N], tot, mn[N << 1][21], lg2[N << 1], dep[N];
int p[N], n, a[N], first[N], efn, inv[N];
int f[N], g[N], sta[N], siz, num[N], ans;
void addedge(int, int);
void dfs(int, int);
bool cmp(int x, int y) { return dfn[fx[x]] < dfn[fx[y]]; }
void init(int);
int lca(int, int);
int main() {
  scanf("%d", &n);
  init(n);
  for (int i = 1; i <= n; i++) p[i] = i;
  lg2[0] = -1;
  for (int i = 1; i <= n + n; i++) lg2[i] = lg2[i / 2] + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    fx[a[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addedge(x, y);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) q2[j].push_back(i);
  }
  sort(p + 1, p + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < q2[p[i]].size(); j++)
      q[q2[p[i]][j]].push_back(fx[p[i]]);
  }
  for (int i = 1; i <= 20; i++)
    for (int j = 1; j <= tot; j++) {
      int w = min(tot, j + (1 << i - 1));
      mn[j][i] =
          dfn[mn[j][i - 1]] < dfn[mn[w][i - 1]] ? mn[j][i - 1] : mn[w][i - 1];
    }
  for (int i = 1; i <= n; i++) {
    siz = 0;
    int sum = 0;
    for (int j = 1; j < q[i].size(); j++) {
      int w = lca(q[i][j - 1], q[i][j]);
      int cnt = phi[a[q[i][j - 1]]];
      while (siz > 0 && dep[w] <= dep[sta[siz]]) {
        f[i] = add(f[i],
                   mod - (long long)dep[sta[siz]] * cnt % mod * num[siz] % mod);
        cnt = add(cnt, num[siz]);
        siz--;
      }
      num[++siz] = cnt;
      sta[siz] = w;
    }
    int cnt = phi[a[q[i][q[i].size() - 1]]];
    while (siz) {
      f[i] = add(f[i],
                 mod - (long long)dep[sta[siz]] * cnt % mod * num[siz] % mod);
      cnt = add(cnt, num[siz]);
      siz--;
    }
    f[i] = add(f[i], f[i]);
    for (int j = 0; j < q[i].size(); j++) {
      sum = add(sum, phi[a[q[i][j]]]);
    }
    for (int j = 0; j < q[i].size(); j++)
      f[i] = add(f[i], (long long)add(sum, mod - phi[a[q[i][j]]]) *
                           phi[a[q[i][j]]] % mod * dep[q[i][j]] % mod);
    f[i] = add(f[i], f[i]);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; i * j <= n; j++)
      g[i] = add(g[i], (long long)mu[j] * f[i * j] % mod);
  for (int i = 1; i <= n; i++)
    ans = add(ans, (long long)g[i] * i % mod * inv[phi[i]] % mod);
  printf("%d\n",
         (long long)ans * power((long long)n * (n - 1) % mod, mod - 2) % mod);
  return 0;
}
void init(int p) {
  inv[1] = 1;
  for (int i = 2; i <= p; i++)
    inv[i] = mod - (long long)mod / i * inv[mod % i] % mod;
  phi[1] = 1;
  mu[1] = 1;
  for (int i = 2; i <= p; i++) {
    if (bo[i] == 0) pri[++len] = i, phi[i] = i - 1, mu[i] = mod - 1;
    for (int j = 1; j <= len && i * pri[j] <= p; j++) {
      int u = i * pri[j];
      bo[u] = 1;
      if (i % pri[j])
        phi[u] = phi[i] * phi[pri[j]], mu[u] = mod - mu[i];
      else {
        phi[u] = phi[i] * pri[j];
        break;
      }
    }
  }
}
void addedge(int x, int y) {
  edge[++efn].end = y;
  edge[efn].next = first[x];
  first[x] = efn;
  edge[++efn].end = x;
  edge[efn].next = first[y];
  first[y] = efn;
}
void dfs(int x, int y) {
  dfn[x] = ++tot;
  dep[x] = dep[y] + 1;
  mn[tot][0] = x;
  for (int h = first[x]; h; h = edge[h].next) {
    int u = edge[h].end;
    if (u != y) {
      dfs(u, x);
      mn[++tot][0] = x;
    }
  }
}
int lca(int x, int y) {
  x = dfn[x];
  y = dfn[y];
  int w = (y - x + 1);
  w = lg2[w];
  return dfn[mn[x][w]] < dfn[mn[y - (1 << w) + 1][w]] ? mn[x][w]
                                                      : mn[y - (1 << w) + 1][w];
}
