#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const long long linf = 1ll << 60;
const double dinf = 1e60;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
inline char mygetchar() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
template <typename T>
inline bool chkmax(T &x, const T &y) {
  return y > x ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T &x, const T &y) {
  return y < x ? x = y, 1 : 0;
}
const int maxn = 2e5 + 100;
const int lgn = 18;
const int mod = 1e9 + 7;
int n, m, ans;
int a[maxn], b[maxn], f[maxn], par[maxn][lgn], dep[maxn], dfn[maxn], End[maxn],
    phi[maxn], x[maxn], y[maxn], inv[maxn];
vector<int> g[maxn], ng[maxn];
bool imp[maxn], isp[maxn];
int pow_mod(int x, int n) {
  int y = 1;
  while (n) {
    if (n & 1) y = 1ll * y * x % mod;
    x = 1ll * x * x % mod;
    n >>= 1;
  }
  return y;
}
void dfs1(int u, int p) {
  dep[u] = dep[p] + 1;
  par[u][0] = p;
  for (int i = 0, _end_ = (lgn - 1); i < _end_; ++i)
    par[u][i + 1] = par[par[u][i]][i];
  dfn[u] = ++m;
  for (int v : g[u])
    if (v != p) dfs1(v, u);
  End[u] = m;
  return;
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  for (int i = 0, _end_ = (lgn); i < _end_; ++i)
    if ((d >> i) & 1) u = par[u][i];
  if (u == v) return u;
  for (int i = (lgn)-1; i >= 0; --i)
    if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
  return par[u][0];
}
void merge(int u, int phi, int dep) {
  (ans += 1ll * x[u] * phi % mod * (dep - 2 * ::dep[u]) % mod) %= mod;
  (ans += 1ll * y[u] * phi % mod) %= mod;
  return;
}
void ins(int u, int phi, int dep) {
  (x[u] += phi) %= mod;
  (y[u] += 1ll * phi * dep % mod) %= mod;
  return;
}
void merge(int u, int rt) {
  if (imp[u]) merge(rt, phi[a[u]], dep[u]);
  for (int v : ng[u]) merge(v, rt);
  return;
}
void ins(int u, int rt) {
  if (imp[u]) ins(rt, phi[a[u]], dep[u]);
  for (int v : ng[u]) ins(v, rt);
  return;
}
int dfs(int u) {
  int hs = 0, son = 0, siz = 1;
  for (int v : ng[u]) {
    int tmp = dfs(v);
    siz += tmp;
    if (chkmax(hs, tmp)) son = v;
  }
  if (!son) {
    if (imp[u]) {
      x[u] = phi[a[u]];
      y[u] = 1ll * x[u] * dep[u] % mod;
    }
    return siz;
  }
  x[u] = x[son];
  y[u] = y[son];
  if (imp[u]) merge(u, phi[a[u]], dep[u]), ins(u, phi[a[u]], dep[u]);
  for (int v : ng[u])
    if (v != son) merge(v, u), ins(v, u);
  return siz;
}
int main() {
  scf(n);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) scf(a[i]), b[a[i]] = i;
  for (int i = (2), _end_ = (n); i <= _end_; ++i) isp[i] = 1;
  phi[1] = 1;
  static vector<int> pme;
  for (int i = (2), _end_ = (n); i <= _end_; ++i) {
    if (isp[i]) pme.push_back(i), phi[i] = i - 1;
    for (int p : pme) {
      if (p * i > n) break;
      isp[p * i] = 0;
      if (i % p == 0) {
        phi[i * p] = phi[i] * p;
        break;
      }
      phi[i * p] = phi[i] * phi[p];
    }
  }
  for (int i = (1), _end_ = (n); i <= _end_; ++i)
    inv[i] = pow_mod(phi[i], mod - 2);
  for (int i = 0, _end_ = (n - 1); i < _end_; ++i) {
    int u, v;
    scf(u, v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs1(1, 0);
  auto cmp = [&](int a, int b) { return dfn[a] < dfn[b]; };
  for (int d = (1), _end_ = (n); d <= _end_; ++d) {
    static vector<int> tmp, all, stk;
    tmp.clear();
    stk.clear();
    for (int i = d; i <= n; i += d) tmp.push_back(b[i]);
    sort(tmp.begin(), tmp.end(), cmp);
    all = tmp;
    for (int i = 0, _end_ = ((int)tmp.size() - 1); i < _end_; ++i)
      all.push_back(lca(tmp[i], tmp[i + 1]));
    sort(all.begin(), all.end(), cmp);
    all.resize(unique(all.begin(), all.end()) - all.begin());
    for (int u : all) ng[u].clear(), imp[u] = 0, x[u] = y[u] = 0;
    for (int u : tmp) imp[u] = 1;
    int root;
    for (int u : all) {
      while ((int)stk.size() &&
             !(dfn[stk.back()] <= dfn[u] && dfn[u] <= End[stk.back()]))
        stk.pop_back();
      if (!(int)stk.size())
        root = u;
      else
        ng[stk.back()].push_back(u);
      stk.push_back(u);
    }
    ans = 0;
    dfs(root);
    f[d] = (ans + ans) % mod;
  }
  for (int d = (n), _end_ = (1); d >= _end_; --d)
    for (int i = d + d; i <= n; i += d) (f[d] -= f[i]) %= mod;
  int ans = 0;
  for (int d = (1), _end_ = (n); d <= _end_; ++d) {
    ((f[d] %= mod) += mod) %= mod;
    (ans += 1ll * f[d] * d % mod * inv[d] % mod) %= mod;
  }
  printf("%d\n", 1ll * ans * pow_mod(1ll * n * (n - 1) % mod, mod - 2) % mod);
  return 0;
}
