#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  static char c;
  static int f;
  x = 0;
  f = 1;
  while (c = getchar(), c < 48)
    if (c == '-') f = -1;
  do x = (x * 10) + (c & 15);
  while (c = getchar(), c > 47);
  x *= f;
}
template <class T>
void prin(T x) {
  if (x < 0)
    x = -x, putchar('-');
  else if (!x) {
    putchar('0');
    return;
  }
  static int tp, stk[100];
  while (x) stk[tp++] = x % 10, x /= 10;
  while (tp) putchar(stk[--tp] ^ 48);
}
template <class T>
void ptn(T x) {
  prin(x);
  putchar('\n');
}
template <class T>
void ptk(T x) {
  prin(x);
  putchar(' ');
}
template <class T>
void Min(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
void Max(T &a, T b) {
  if (a < b) a = b;
}
const int N = (int)2e5 + 5, mod = (int)1e9 + 7;
int head[N], tp[N], sz[N], son[N], par[N], dep[N], dfn[N], post[N], tot_edge;
pair<int, int> G[N << 1];
int n, a[N], pr[N], pr_pow[N], phi[N], inv[N], prime[N >> 1], prime_cnt, mu[N];
void init() {
  phi[1] = mu[1] = inv[1] = 1;
  ++n;
  for (int i = (2), _t = (n); i < _t; ++i) {
    inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
    if (!pr[i]) pr[i] = pr_pow[i] = prime[prime_cnt++] = i;
    if (pr_pow[i] == i)
      phi[i] = i - i / pr[i], mu[i] = -(pr[i] == i);
    else
      phi[i] = phi[i / pr_pow[i]] * phi[pr_pow[i]],
      mu[i] = mu[i / pr_pow[i]] * mu[pr_pow[i]];
    for (int j = 0, p, t;
         j < prime_cnt && (p = prime[j]) <= pr[i] && (t = i * p) < n; ++j) {
      pr[t] = p;
      pr_pow[t] = pr[i] == p ? p * pr_pow[i] : p;
    }
  }
  --n;
}
void pre_dfs(int x) {
  sz[x] = 1;
  for (int i = head[x]; i; i = G[i].second) {
    int y = G[i].first;
    if (y == par[x]) continue;
    par[y] = x;
    dep[y] = dep[x] + 1;
    pre_dfs(y);
    sz[x] += sz[y];
    if (sz[y] > sz[son[x]]) son[x] = y;
  }
}
void rdfs(int x) {
  static int dfn_clock;
  dfn[x] = ++dfn_clock;
  if (son[x]) {
    tp[son[x]] = tp[x];
    rdfs(son[x]);
  }
  for (int i = head[x]; i; i = G[i].second) {
    int y = G[i].first;
    if (y == par[x] || y == son[x]) continue;
    rdfs(tp[y] = y);
  }
  post[x] = dfn_clock;
}
int LCA(int x, int y) {
  while (tp[x] != tp[y]) {
    if (dep[tp[x]] > dep[tp[y]])
      x = par[tp[x]];
    else
      y = par[tp[y]];
  }
  if (dep[x] < dep[y]) return x;
  return y;
}
void add_mod(int &a, int b) {
  if ((a += b) >= mod) a -= mod;
}
void del_mod(int &a, int b) {
  if ((a -= b) < 0) a += mod;
}
int f[N], Mp[N], que[N], que_cnt, sum_phi, sum[N], lst[N], ans;
pair<int, int> E[N];
bool mark[N], flag[N];
bool cmp(const int a, const int &b) { return dfn[a] < dfn[b]; }
void dfs(int x) {
  if (flag[x])
    sum[x] = phi[a[x]];
  else
    sum[x] = 0;
  for (int i = lst[x]; i; i = E[i].second) {
    int y = E[i].first;
    dfs(y);
    ans = (ans +
           (sum_phi - sum[y]) * (long long)sum[y] % mod * (dep[y] - dep[x])) %
          mod;
    add_mod(sum[x], sum[y]);
  }
}
int calc(int step) {
  sum_phi = que_cnt = ans = 0;
  for (int i = step; i <= n; i += step) {
    que[que_cnt++] = Mp[i];
    flag[Mp[i]] = mark[Mp[i]] = true;
    add_mod(sum_phi, phi[i]);
  }
  sort(que, que + que_cnt, cmp);
  for (int i = (1), _t = (que_cnt); i < _t; ++i) {
    int anc = LCA(que[i], que[i - 1]);
    if (!mark[anc]) {
      que[que_cnt++] = anc;
      mark[anc] = true;
    }
  }
  sort(que, que + que_cnt, cmp);
  static int stk[N], tp;
  lst[stk[tp = 0] = que[0]] = 0;
  for (int i = (1), _t = (que_cnt); i < _t; ++i) {
    while (tp && dfn[que[i]] > post[stk[tp]]) --tp;
    E[i] = pair<int, int>(que[i], lst[stk[tp]]);
    lst[stk[tp]] = i;
    stk[++tp] = que[i];
    lst[que[i]] = 0;
  }
  dfs(que[0]);
  for (int i = (0), _t = (que_cnt); i < _t; ++i)
    flag[que[i]] = mark[que[i]] = false;
  return ans;
}
int main() {
  rd(n);
  for (int i = (1), _t = (n + 1); i < _t; ++i) rd(a[i]), Mp[a[i]] = i;
  init();
  for (int x, y, i = 1; i < n; ++i) {
    rd(x), rd(y);
    G[++tot_edge] = pair<int, int>(y, head[x]);
    head[x] = tot_edge;
    G[++tot_edge] = pair<int, int>(x, head[y]);
    head[y] = tot_edge;
  }
  pre_dfs(1);
  rdfs(tp[1] = 1);
  int ans = 0;
  for (int i = (n + 1) - 1, _s = (1); i >= _s; --i) {
    f[i] = calc(i);
    for (int j = i << 1; j <= n; j += i) del_mod(f[i], f[j]);
    ans = (ans + (long long)i * inv[phi[i]] % mod * f[i]) % mod;
  }
  add_mod(ans, ans);
  ans = (long long)ans * inv[n] % mod * inv[n - 1] % mod;
  ptn(ans);
  return 0;
}
