#include <bits/stdc++.h>
using namespace std;
int p1 = 1000000, p2 = 0;
char buf[1000005], wb[1000005];
int gc() {
  if (p1 >= 1000000) fread(buf, 1, 1000000, stdin), p1 = 0;
  return buf[p1++];
}
long long getint() {
  long long ret = 0, flag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    ret = (ret << 3) + (ret << 1) + c - '0';
    c = getchar();
  }
  return ret * flag;
}
void pc(char x) {
  if (p2 >= 1000000) fwrite(wb, 1, 1000000, stdout), p2 = 0;
  wb[p2++] = x;
}
void wrt(long long x) {
  if (x < 0) pc('-'), x = -x;
  int c[24] = {0};
  if (!x) return pc('0'), void();
  while (x) c[++c[0]] = x % 10, x /= 10;
  while (c[0]) pc(c[c[0]--] + '0');
}
long long ksm(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % int(1e9 + 7);
    a = a * a % int(1e9 + 7), b >>= 1;
  }
  return ret;
}
int n, a[200005];
struct edge {
  int ne, v;
} e[400005];
int head[200005], cnt;
void add(int u, int v) {
  ++cnt;
  e[cnt].v = v;
  e[cnt].ne = head[u];
  head[u] = cnt;
}
int po[200005];
int dep[200005], fa[200005], p[400005][20], rd[400005], sign;
void dfs(int x, int prt) {
  fa[x] = prt, dep[x] = dep[prt] + 1;
  p[x][0] = prt, rd[x] = ++sign;
  for (int i = 1; i < 20; i++) p[x][i] = p[p[x][i - 1]][i - 1];
  for (int i = head[x]; i; i = e[i].ne) {
    int y = e[i].v;
    if (y == prt) continue;
    dfs(y, x);
  }
}
int LCA(int x, int y) {
  if (!x || !y) return x | y;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = log2(dep[x] - dep[y]); i >= 0; i--) {
    if (dep[p[x][i]] >= dep[y]) x = p[x][i];
  }
  if (x == y) return x;
  for (int i = log2(dep[x]); i >= 0; i--) {
    if (p[x][i] ^ p[y][i]) x = p[x][i], y = p[y][i];
  }
  return p[x][0];
}
int prim[200005];
long long mul[200005], phi[200005];
bool vst[200005];
vector<int> vec[200005];
bool cmp(int x, int y) { return rd[x] < rd[y]; }
bool vt[200005];
long long s1[200005], s2[200005], ans;
void dfs1(int x, int prt, long long &ret) {
  if (vt[x])
    s1[x] = phi[a[x]], s2[x] = phi[a[x]] * dep[x] % int(1e9 + 7), vt[x] = 0;
  else
    s1[x] = s2[x] = 0;
  for (auto y : vec[x]) {
    if (y == prt) continue;
    dfs1(y, x, ret), ret = (ret + s2[x] * s1[y] % int(1e9 + 7) +
                            s1[x] * s2[y] % int(1e9 + 7) -
                            s1[x] * s1[y] % int(1e9 + 7) * dep[x] %
                                int(1e9 + 7) * 2ll % int(1e9 + 7) +
                            int(1e9 + 7)) %
                           int(1e9 + 7);
    s1[x] = (s1[x] + s1[y]) % int(1e9 + 7),
    s2[x] = (s2[x] + s2[y]) % int(1e9 + 7);
  }
  vec[x].clear();
}
int S[200005];
void SvT(int d) {
  static int p[200005], s[200005];
  int k = 0, tot, Lca = 0, tp = 0;
  long long ret = 0;
  for (int i = d; i <= n; i += d) p[tot = ++k] = po[i];
  for (int i = 1; i <= k; i++) Lca = LCA(p[i], Lca), vt[p[i]] = 1;
  sort(p + 1, p + k + 1, cmp), s[++tp] = Lca;
  for (int i = 1; i <= tot; i++) {
    if (p[i] == Lca) continue;
    int lca = LCA(p[i], s[tp]);
    while (lca != s[tp]) {
      if (dep[s[tp - 1]] < dep[lca]) {
        vec[lca].push_back(s[tp--]);
        if (s[tp] != p[i] && lca != Lca && lca != s[tp]) s[++tp] = lca;
        break;
      }
      vec[s[tp - 1]].push_back(s[tp]), tp--;
    }
    if (s[tp] != p[i]) s[++tp] = p[i];
  }
  while (--tp) vec[s[tp]].push_back(s[tp + 1]);
  dfs1(Lca, 0, ret), s1[Lca] = 0;
  ans = (ans + S[d] * ret % int(1e9 + 7)) % int(1e9 + 7);
}
int main() {
  mul[1] = 1, phi[1] = 1;
  for (int i = 2; i <= 200000; i++) {
    if (!vst[i]) prim[++prim[0]] = i, mul[i] = int(1e9 + 7) - 1, phi[i] = i - 1;
    for (int j = 1; j <= prim[0] && i * prim[j] <= 200000; j++) {
      int x = i * prim[j];
      vst[x] = 1;
      if (i % prim[j] == 0) {
        phi[x] = phi[i] * prim[j];
        break;
      }
      mul[x] = int(1e9 + 7) - mul[i];
      phi[x] = phi[i] * (prim[j] - 1);
    }
  }
  for (int i = 1; i <= 200000; i++) {
    long long iv = 1ll * i * ksm(phi[i], int(1e9 + 7) - 2) % int(1e9 + 7);
    for (int j = 1; i * j <= 200000; j++)
      S[i * j] = (S[i * j] + iv * mul[j] % int(1e9 + 7)) % int(1e9 + 7);
  }
  n = getint();
  for (int i = 1; i <= n; i++) po[a[i] = getint()] = i;
  for (int i = 1; i < n; i++) {
    int u = getint(), v = getint();
    add(u, v), add(v, u);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) SvT(i);
  wrt(ans * ksm(n, int(1e9 + 7) - 2) % int(1e9 + 7) *
      ksm(n - 1, int(1e9 + 7) - 2) % int(1e9 + 7) * 2 % int(1e9 + 7)),
      pc('\n');
  fwrite(wb, 1, p2, stdout);
  return 0;
}
