#include <bits/stdc++.h>
using namespace std;
int n, x, y;
long long res;
int a[200007];
int phi[200007];
vector<int> divs[200007];
vector<int> G[200007];
bitset<200007> del;
bitset<200007> vis;
int sub[200007];
int max_sub[200007];
int inv[200007];
int depth[200007];
long long sum_phi[200007];
long long sum[200007];
vector<int> curr, comp;
long long fpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a % 1000000007;
  if (b % 2)
    return (a % 1000000007 * fpow(a, b - 1)) % 1000000007;
  else {
    long long q = fpow(a, b / 2);
    return (q * q) % 1000000007;
  }
}
void dfs1(int v) {
  curr.push_back(v);
  vis[v] = 1;
  max_sub[v] = 0;
  sub[v] = 1;
  for (auto it : G[v]) {
    if (!del[it] && !vis[it]) {
      dfs1(it);
      sub[v] += sub[it];
      max_sub[v] = max(max_sub[v], sub[it]);
    }
  }
}
void dfs2(int v) {
  comp.push_back(v);
  vis[v] = 1;
  for (auto it : G[v]) {
    if (!del[it] && !vis[it]) {
      depth[it] = depth[v] + 1;
      dfs2(it);
    }
  }
}
void solve(int s) {
  curr.clear();
  dfs1(s);
  for (auto v : curr) {
    max_sub[v] = max(max_sub[v], (int)curr.size() - sub[v]);
  }
  for (auto &v : curr) {
    if (max_sub[v] < max_sub[curr[0]]) swap(v, curr[0]);
  }
  for (auto v : curr) {
    for (auto d : divs[v]) sum_phi[d] += phi[v];
    vis[v] = 0;
  }
  vis[curr[0]] = 1;
  for (auto v : G[curr[0]]) {
    if (!del[v]) {
      comp.clear();
      depth[v] = 1;
      dfs2(v);
      for (auto it : comp) {
        for (auto d : divs[it]) sum_phi[d] -= phi[it];
      }
      for (auto it : comp) {
        for (int i = divs[it].size() - 1; i >= 0; --i) {
          int d = divs[it][i];
          sum[d] += sum_phi[d];
          res += 2ll * phi[it] % 1000000007 * depth[it] % 1000000007 * d %
                 1000000007 * inv[phi[d]] % 1000000007 * sum[d] % 1000000007;
          res %= 1000000007;
          for (auto x : divs[d]) sum[x] -= sum[d];
        }
        for (auto d : divs[it]) sum[d] = 0;
      }
      for (auto it : comp) {
        for (auto d : divs[it]) sum_phi[d] += phi[it];
      }
    }
  }
  for (auto v : curr) {
    for (auto d : divs[v]) sum_phi[d] -= phi[v];
    vis[v] = 0;
  }
  del[curr[0]] = 1;
  for (auto v : G[curr[0]]) {
    if (!del[v]) solve(v);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    inv[i] = fpow(i, 1000000007 - 2);
  }
  for (int i = 1; i <= n; ++i) {
    phi[i] = i;
  }
  for (int i = 2; i <= n; ++i) {
    if (phi[i] == i) {
      for (int j = i; j <= n; j += i) {
        phi[j] -= phi[j] / i;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      divs[j].push_back(i);
    }
  }
  for (int i = 1; i < n; ++i) {
    cin >> x >> y;
    G[a[x]].push_back(a[y]);
    G[a[y]].push_back(a[x]);
  }
  solve(1);
  cout << (res * fpow((long long)n * (n - 1), 1000000007 - 2)) % 1000000007;
}
