#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T, class U>
inline void print(T first, U second) {
  printsp(first);
  println(second);
}
template <class T, class U, class V>
inline void print(T first, U second, V z) {
  printsp(first);
  printsp(second);
  println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int phi[200010], flag[200010], prime[200010], ff[200010];
int a[200010], dp[200010], head[200010], fac[20];
int to[200010 << 1], nxt[200010 << 1], E, id[200010];
int st[200010], ed[200010], tot, val[200010], ans[200010], q[200010];
int vst[200010], fflag[200010], vflag, inv[200010], tval[200010], pa[200010];
vector<int> V[200010];
void add_edge(int u, int v) {
  to[E] = v;
  nxt[E] = head[u];
  head[u] = E++;
}
struct Cmp {
  bool operator()(const pair<int, int> &a, const pair<int, int> &b) const {
    if (dp[a.first] != dp[b.first]) return dp[a.first] > dp[b.first];
    return a.second < b.second;
  }
};
int p[200010][20];
set<pair<int, int>, Cmp> S;
struct LCA {
  void dfs(int u = 1, int fa = 0) {
    p[u][0] = fa;
    dp[u] = dp[fa] + 1;
    st[u] = ++tot;
    for (int i = 1; i < 18; i++) p[u][i] = p[p[u][i - 1]][i - 1];
    for (int e = head[u]; e != -1; e = nxt[e]) {
      int v = to[e];
      if (v == fa) continue;
      dfs(v, u);
    }
    ed[u] = tot;
  }
  int k_th(int u, int k) {
    for (int i = 0; i < 18; i++) {
      if (k & (1 << i)) u = p[u][i];
    }
    return u;
  }
  int lca(int a, int b) {
    if (dp[a] > dp[b]) swap(a, b);
    b = k_th(b, dp[b] - dp[a]);
    if (a == b) return a;
    for (int i = 18; i >= 0; i--) {
      if (p[a][0] == p[b][0]) break;
      if (p[a][i] != p[b][i]) a = p[a][i], b = p[b][i];
    }
    return p[a][0];
  }
} lca;
int cmp(int u, int v) { return st[u] < st[v]; }
int sum[200010], tmp[200010];
void dfs(int u, int k) {
  sum[u] = 0;
  long long mid = 0, tp = 0;
  for (int e = head[u]; ~e; e = nxt[e]) {
    int v = to[e];
    dfs(v, k);
    mid += (long long)sum[v] * sum[v] % 1000000007;
    tp += sum[v];
  }
  mid %= 1000000007;
  tp %= 1000000007;
  sum[u] = (tp + a[u] * (fflag[u] == vflag)) % 1000000007;
  tmp[u] = (tp * tp - mid + 2LL * tp * a[u] * (fflag[u] == vflag)) % 1000000007;
  if (tmp[u] < 0) tmp[u] += 1000000007;
  ans[k] -= (long long)dp[u] * tmp[u] % 1000000007;
  if (ans[k] < 0) ans[k] += 1000000007;
}
int main() {
  int n, np = 0, u, v;
  memset(head, -1, sizeof(head));
  ff[1] = tval[1] = 1;
  phi[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 200010; i++)
    inv[i] = (long long)1000000007 / i * (1000000007 - inv[1000000007 % i]) %
             1000000007;
  for (int i = 2; i < 200010; i++) {
    if (!flag[i]) prime[np++] = i, flag[i] = i;
    for (int j = 0; j < np && prime[j] * i < 200010; j++) {
      flag[prime[j] * i] = prime[j];
      if (flag[i] == prime[j]) break;
    }
    int v = i / flag[i];
    if (flag[v] == flag[i])
      ff[i] = ff[v], tval[i] = tval[v], phi[i] = phi[v] * flag[i];
    else
      ff[i] = ff[v] * flag[i],
      tval[i] = (long long)tval[v] * flag[i] % 1000000007 * inv[(flag[i] - 1)] %
                1000000007,
      phi[i] = phi[v] * (flag[i] - 1);
  }
  gn(n);
  for (int i = 1; i <= n; i++) gn(a[i]);
  for (int i = 1; i < n; i++) {
    gn(u, v);
    add_edge(u, v);
    add_edge(v, u);
  }
  lca.dfs();
  for (int i = 0; i < n; i++) id[i] = i + 1;
  sort(id, id + n, cmp);
  val[0] = 1;
  for (int k = 0; k < n; k++) {
    int cnt = 0, i = id[k];
    for (int u = a[i]; u > 1;) {
      int v = flag[u];
      while (u % v == 0) u /= v;
      fac[cnt++] = v;
    }
    V[1].push_back(i);
    for (int j = 1; j < 1 << cnt; j++) {
      val[j] = val[j ^ (j & -j)] * fac[(__builtin_ctz(j))];
      V[val[j]].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) a[i] = phi[a[i]];
  memset(head, -1, sizeof head);
  for (int i = 1; i <= n; i++)
    if (V[i].size() > 1) {
      int sum = 0, nn = V[i].size();
      for (int j = 0; j < nn; j++) id[j] = V[i][j];
      for (int j = 0; j < nn; j++) sum = (sum + a[id[j]]) % 1000000007;
      ans[i] = 0;
      for (int j = 0; j < nn; j++)
        ans[i] = (ans[i] + (long long)dp[id[j]] * a[id[j]] % 1000000007 *
                               (sum + 1000000007 - a[id[j]])) %
                 1000000007;
      ++vflag;
      int qb = 0;
      for (int j = 0; j < nn; j++)
        pa[id[j]] = -1, vst[id[j]] = vflag, fflag[id[j]] = vflag,
        q[qb++] = id[j];
      int root = lca.lca(id[0], id[nn - 1]);
      for (int j = 1; j < nn; j++) {
        u = lca.lca(id[j - 1], id[j]);
        if (vst[u] != vflag) vst[u] = vflag, q[qb++] = u;
        pa[id[j]] = u;
        v = id[j - 1];
        if (v != u) {
          while (pa[v] != -1) {
            if (dp[pa[v]] <= dp[u]) break;
            v = pa[v];
          }
          if (pa[v] != u) pa[u] = pa[v], pa[v] = u;
        }
      }
      for (int j = 0; j < qb; j++) head[q[j]] = -1;
      E = 0;
      for (int j = 0; j < qb; j++)
        if (pa[q[j]] != -1) add_edge(pa[q[j]], q[j]);
      dfs(root, i);
    }
  long long res = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = i << 1; j <= n; j += i)
      ans[i] = (ans[i] + 1000000007 - ans[j]) % 1000000007;
    res += (long long)ans[i] * tval[i] % 1000000007;
    res %= 1000000007;
  }
  println(2LL * res * inv[n] % 1000000007 * inv[n - 1] % 1000000007);
  return 0;
}
