#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 2e5 + 10, K = 22;
void Init();
long long Calc(int dg);
int BuildVirt(int dg);
void dfs1(int u, int ff);
int lca(int u, int v);
long long dfs2(int u, int dg);
long long dfs3(int u, long long cur, long long Sum);
struct Edge {
  int to, dis, nx;
} edg[N * 3];
vector<int> keyp[N], g[N], fact[N];
int a[N], n, ky[N], kn, sk[N], skn, g2[N], pn, prime[N], sz[N], dfn[N],
    dfs_clock = 0, dep[N], jp[N][K], edgn = 0;
int val[N];
bool vis[N];
long long prod[N], inv[N], phi[N], pr[N], s[N];
bool cmpdfn(int u, int v) { return dfn[u] < dfn[v]; }
void AddEdg(int ff, int u) {
  edg[edgn] = (Edge){u, dep[u] - dep[ff], g2[ff]};
  g2[ff] = edgn++;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  Init();
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs1(1, -1);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    long long f = Calc(i), g = prod[i];
    ans = (ans + f * g) % MOD;
  }
  ans = ans * inv[n] % MOD * inv[n - 1] % MOD;
  cout << ans << endl;
  return 0;
}
void Init() {
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; ++i) inv[i] = (MOD - inv[MOD % i]) * (MOD / i) % MOD;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j < K; ++j) jp[i][j] = -1;
  phi[1] = prod[1] = 1;
  for (int i = 1; i <= n; ++i) pr[i] = i;
  pn = 0;
  for (int i = 2; i <= n; ++i) {
    if (pr[i] == i) prime[pn++] = i;
    for (int j = 0; j < pn && prime[j] <= pr[i] && i <= n / prime[j]; ++j)
      pr[i * prime[j]] = prime[j];
    int pre = i / pr[i];
    if (pr[i] != pr[pre])
      prod[i] = prod[pre] * inv[pr[i] - 1] % MOD,
      phi[i] = phi[pre] * (pr[i] - 1);
    else
      prod[i] = 0, phi[i] = phi[pre] * pr[i];
  }
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; j += i) fact[j].push_back(i);
  for (int i = 1; i <= n; ++i)
    for (int ai = a[i], j = 0; j < fact[ai].size(); ++j)
      keyp[fact[ai][j]].push_back(i);
}
long long Calc(int dg) {
  int rt = BuildVirt(dg);
  long long initres = dfs2(rt, dg);
  return dfs3(rt, initres, s[rt]);
}
int BuildVirt(int dg) {
  for (int i = 0; i < (kn = keyp[dg].size()); ++i)
    vis[ky[i] = keyp[dg][i]] = true;
  sort(ky, ky + kn, cmpdfn);
  for (int i = 0, m = kn, c; i + 1 < m; ++i)
    if (!vis[c = lca(ky[i], ky[i + 1])]) vis[ky[kn++] = c] = true;
  sort(ky, ky + kn, cmpdfn);
  edgn = 0;
  for (int i = 0; i < kn; ++i) g2[ky[i]] = -1;
  skn = 0;
  sk[skn++] = ky[0];
  for (int i = 1; i < kn; sk[skn++] = ky[i++]) {
    while (dfn[sk[skn - 1]] + sz[sk[skn - 1]] <= dfn[ky[i]]) --skn;
    AddEdg(sk[skn - 1], ky[i]);
  }
  for (int i = 0; i < kn; ++i) vis[ky[i]] = false;
  return ky[0];
}
void dfs1(int u, int ff) {
  sz[u] = 1;
  dfn[u] = ++dfs_clock;
  jp[u][0] = ff;
  if (ff != -1) {
    for (int k = 0; jp[jp[u][k]][k] != -1; ++k) jp[u][k + 1] = jp[jp[u][k]][k];
    dep[u] = dep[ff] + 1;
  } else
    dep[u] = 0;
  for (int i = 0, v; i < g[u].size(); ++i)
    if ((v = g[u][i]) != ff) {
      dfs1(v, u);
      sz[u] += sz[v];
    }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int step = dep[u] - dep[v], i = 0; step; step >>= 1, ++i)
    if (step & 1) u = jp[u][i];
  if (u == v) return u;
  for (int k = 20; ~k; --k)
    if (jp[u][k] != jp[v][k]) u = jp[u][k], v = jp[v][k];
  return jp[u][0];
}
long long dfs2(int u, int dg) {
  if (a[u] % dg == 0)
    val[u] = phi[a[u]];
  else
    val[u] = 0;
  s[u] = val[u];
  long long sum = 0;
  for (int i = g2[u]; ~i; i = edg[i].nx) {
    Edge e = edg[i];
    sum += (dfs2(e.to, dg) + s[e.to] * e.dis) % MOD;
    s[u] = (s[u] + s[e.to]) % MOD;
  }
  return sum;
}
long long dfs3(int u, long long cur, long long Sum) {
  long long res = cur * val[u] % MOD;
  for (int i = g2[u]; ~i; i = edg[i].nx) {
    Edge e = edg[i];
    long long nx =
        (cur + e.dis * ((Sum - s[e.to] + MOD - s[e.to]) % MOD)) % MOD;
    res = (res + dfs3(e.to, nx, Sum)) % MOD;
  }
  return res;
}
