#include <bits/stdc++.h>
using namespace std;
const int N = 200005, mod = 1e9 + 7;
char buf[1 << 20], *p1, *p2;
inline int _R() {
  int d = 0;
  bool ty = 1;
  char t;
  while (t = ((p1 == p2 &&
               (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2))
                  ? 0
                  : *p1++),
         (t < '0' || t > '9') && t != '-')
    ;
  t == '-' ? (ty = 0) : (d = t - '0');
  while (t = ((p1 == p2 &&
               (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2))
                  ? 0
                  : *p1++),
         t >= '0' && t <= '9')
    d = (d << 3) + (d << 1) + t - '0';
  return ty ? d : -d;
}
inline int add(int a, int b) {
  a += b;
  return a >= mod ? a - mod : a;
}
inline int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + mod : a;
}
inline int mul(int a, int b) { return 1LL * a * b % mod; }
inline int ksm(int a, int b) {
  int r;
  for (r = 1; b; b >>= 1, a = mul(a, a))
    if (b & 1) r = mul(r, a);
  return r;
}
inline void inc(int& a, int b) { a = add(a, b); }
inline void dec(int& a, int b) { a = sub(a, b); }
int n, a[N], b[N];
int phi[N], pri[N], vis[N], mu[N];
void euler() {
  phi[1] = mu[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pri[++pri[0]] = i, phi[i] = i - 1, mu[i] = mod - 1;
    for (int j = 1; i * pri[j] <= n && j <= pri[0]; j++) {
      int k = i * pri[j];
      vis[k] = 1;
      if (i % pri[j] == 0) {
        phi[k] = phi[i] * pri[j];
        mu[k] = 0;
        break;
      } else
        mu[k] = mod - mu[i], phi[k] = phi[i] * (pri[j] - 1);
    }
  }
}
int Tote, Last[N], End[N << 1], Next[N << 1];
void ADDE() {
  int x = _R(), y = _R();
  End[++Tote] = y, Next[Tote] = Last[x], Last[x] = Tote;
  End[++Tote] = x, Next[Tote] = Last[y], Last[y] = Tote;
}
int vtt, dfn[N], top[N], fa[N], dep[N], hson[N];
int dfs_init(int x) {
  dfn[x] = ++vtt;
  dep[x] = dep[fa[x]] + 1;
  int i, u, tmp, sz = 1, maxx = 0;
  for (i = Last[x]; i; i = Next[i])
    if (u = End[i], u != fa[x])
      if (fa[u] = x, tmp = dfs_init(u), tmp > maxx) maxx = tmp, hson[x] = u;
  return sz;
}
void dfs_make(int x) {
  if (hson[x]) top[hson[x]] = top[x], dfs_make(hson[x]);
  for (int i = Last[x], u; i; i = Next[i])
    if (u = End[i], u != fa[x] && u != hson[x]) dfs_make(top[u] = u);
}
int lca(int x, int y) {
  while (top[x] != top[y])
    if (dep[top[x]] > dep[top[y]])
      x = fa[top[x]];
    else
      y = fa[top[y]];
  return dep[x] < dep[y] ? x : y;
}
namespace SSS {
int g[N], s[N];
bool cmp(int a, int b) { return dfn[a] < dfn[b]; }
int Tote, Last[N], End[N], Next[N];
void ADDE(int x, int y) {
  End[++Tote] = y, Next[Tote] = Last[x], Last[x] = Tote;
}
int ans;
bool vis[N];
int dp1(int x) {
  int i, u, sum = 0, tt = 0, tmp;
  if (vis[x]) sum = phi[a[x]];
  for (i = Last[x]; i; i = Next[i]) {
    u = End[i];
    tmp = dp1(u);
    inc(tt, mul(sum, tmp));
    inc(sum, tmp);
  }
  dec(ans, mul(add(dep[x], dep[x]), add(tt, tt)));
  return sum;
}
void dp2(int x, int d) {
  if (vis[x]) inc(ans, mul(2, mul(mul(phi[a[x]], dep[x]), sub(d, phi[a[x]]))));
  for (int i = Last[x]; i; i = Next[i]) dp2(End[i], d);
  Last[x] = vis[x] = 0;
}
int solve(int d) {
  int i, t, top = 0, tot = 0;
  Tote = 0;
  for (i = d; i <= n; i += d) g[++tot] = b[i], vis[b[i]] = 1;
  if (tot <= 1) return 0;
  sort(g + 1, g + 1 + tot, cmp);
  s[++top] = 1;
  if (g[1] != 1) s[++top] = g[1];
  for (i = 2; i <= tot; i++) {
    t = lca(g[i - 1], g[i]);
    while (top > 1 && dep[s[top - 1]] >= dep[t]) {
      ADDE(s[top - 1], s[top]);
      top--;
    }
    if (s[top] != t) ADDE(t, s[top]), s[top] = t;
    s[++top] = g[i];
  }
  while (top > 1) ADDE(s[top - 1], s[top]), top--;
  ans = 0;
  dp2(1, dp1(1));
  return ans;
}
}  // namespace SSS
int f[N];
int main() {
  int i, j;
  n = _R(), euler();
  for (i = 1; i <= n; i++) a[i] = _R(), b[a[i]] = i;
  for (i = 1; i < n; i++) ADDE();
  dfs_init(1);
  dfs_make(top[1] = 1);
  for (i = 1; i <= n; i++) f[i] = SSS ::solve(i);
  int ans = 0;
  for (i = 1; i <= n; i++) {
    int tmp = 0;
    for (j = i; j <= n; j += i) inc(tmp, mul(f[j], mu[j / i]));
    inc(ans, mul(tmp, mul(i, ksm(phi[i], mod - 2))));
  }
  printf("%d\n", mul(ans, ksm(mul(n, n - 1), mod - 2)));
}
