#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  char c;
  int num = 0, flg = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flg = -1;
  while (c >= '0' && c <= '9') {
    num = num * 10 + c - 48;
    c = getchar();
  }
  return num * flg;
}
const int mod = 1000000007;
int ksm(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = 1ll * ret * x % mod;
    y >>= 1;
    x = 1ll * x * x % mod;
  }
  return ret;
}
int prime[200005], tot, mu[200005], phi[200005], inv[200005];
bool vis[200005];
void shai() {
  int i, j, n = 200000;
  inv[0] = inv[1] = phi[1] = mu[1] = 1;
  vis[1] = 1;
  for (i = 2; i <= n; i++) {
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
    if (!vis[i]) {
      prime[++tot] = i;
      mu[i] = -1;
      phi[i] = i - 1;
    }
    for (j = 1; j <= tot; j++) {
      int tmp = i * prime[j];
      if (tmp > n) break;
      vis[tmp] = 1;
      if (i % prime[j] == 0) {
        mu[tmp] = 0;
        phi[tmp] = phi[i] * prime[j];
        break;
      }
      mu[tmp] = (mod - mu[i]) % mod;
      phi[tmp] = phi[i] * (prime[j] - 1);
    }
  }
}
int a[200005], fir[200005], to[2 * 200005], nxt[2 * 200005], cd[2 * 200005],
    cnt;
int dep[200005], fa[200005], top[200005], siz[200005], son[200005];
void adde(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  to[++cnt] = b;
  nxt[cnt] = fir[a];
  fir[a] = cnt;
  cd[cnt] = dep[b] - dep[a];
  to[++cnt] = a;
  nxt[cnt] = fir[b];
  fir[b] = cnt;
  cd[cnt] = dep[b] - dep[a];
}
void dfs1(int u) {
  dep[u] = dep[fa[u]] + 1;
  siz[u] = 1;
  for (int v, p = fir[u]; p; p = nxt[p]) {
    if ((v = to[p]) != fa[u]) {
      fa[v] = u;
      dfs1(v);
      siz[u] += siz[v];
      if (siz[son[u]] < siz[v]) son[u] = v;
    }
  }
}
int dfn[200005], dc;
void dfs2(int u) {
  dfn[u] = ++dc;
  if (son[u]) top[son[u]] = top[u], dfs2(son[u]);
  for (int v, p = fir[u]; p; p = nxt[p])
    if ((v = to[p]) != fa[u] && v != son[u]) top[v] = v, dfs2(v);
}
int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return dep[x] < dep[y] ? x : y;
}
int stk[200005], tp, dl[200005], dcnt;
bool ont[200005];
bool cmp(int x, int y) { return dfn[x] < dfn[y]; }
void build() {
  tp = 0;
  sort(dl + 1, dl + dcnt + 1, cmp);
  int i, u, lca, tmp = dcnt;
  if (dl[1] != 1) dl[++dcnt] = 1, stk[++tp] = 1;
  for (i = 1; i <= tmp; i++) {
    ont[u = dl[i]] = 1;
    if (tp <= 1 || (lca = LCA(stk[tp], u)) == stk[tp]) {
      stk[++tp] = u;
      continue;
    }
    while (tp > 1 && dep[stk[tp - 1]] >= dep[lca]) {
      adde(stk[tp - 1], stk[tp]);
      tp--;
    }
    if (lca != stk[tp]) {
      adde(lca, stk[tp]);
      stk[tp] = lca;
      dl[++dcnt] = lca;
    }
    stk[++tp] = u;
  }
  while (tp > 1) {
    adde(stk[tp - 1], stk[tp]);
    tp--;
  }
}
int val[200005], f[200005], g[200005], sum[200005], asum;
void CL() {
  for (int u, i = 1; i <= dcnt; i++) {
    u = dl[i];
    fir[u] = val[u] = 0;
    ont[u] = 0;
  }
  dcnt = cnt = 0;
}
vector<int> id[200005];
int w[200005];
void DP1(int u, int ff) {
  sum[u] = val[u];
  g[u] = f[u] = 0;
  for (int v, p = fir[u]; p; p = nxt[p]) {
    if ((v = to[p]) != ff) {
      DP1(v, u);
      f[u] = (1ll * f[u] + 1ll * f[v] + 1ll * sum[v] * cd[p]) % mod;
      sum[u] = (sum[u] + sum[v]) % mod;
    }
  }
}
void DP2(int u, int ff) {
  for (int v, p = fir[u]; p; p = nxt[p]) {
    if ((v = to[p]) != ff) {
      g[v] =
          (1ll * g[u] + 1ll * (1ll * asum + 2ll * mod - 2ll * sum[v]) * cd[p]) %
          mod;
      DP2(v, u);
    }
  }
}
int main() {
  int n, i, j, k, u, v;
  shai();
  n = gi();
  for (i = 1; i <= n; i++) a[i] = gi(), id[a[i]].push_back(i);
  for (i = 1; i < n; i++) {
    u = gi();
    v = gi();
    adde(u, v);
  }
  dfs1(1);
  top[1] = 1;
  dfs2(1);
  memset(fir, 0, sizeof(fir));
  cnt = 0;
  int ans = 0, su;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i) {
      w[j] = (1ll * w[j] + 1ll * i * inv[phi[i]] % mod * mu[j / i]) % mod;
      for (k = 0; k < int(id[j].size()); k++) {
        u = dl[++dcnt] = id[j][k];
        val[u] = phi[a[u]];
      }
    }
    build();
    DP1(1, 0);
    g[1] = f[1];
    asum = sum[1];
    DP2(1, 0);
    su = 0;
    for (j = 1; j <= dcnt; j++)
      if (ont[u = dl[j]]) su = (1ll * su + 1ll * g[u] * val[u]) % mod;
    ans = (1ll * ans + 1ll * su * w[i]) % mod;
    CL();
  }
  ans = 1ll * ans * inv[n] % mod * inv[n - 1] % mod;
  printf("%d\n", (ans + mod) % mod);
}
