#include <bits/stdc++.h>
using namespace std;
const int MAX = 100010, GENM = 320, M = 1e9 + 7;
bool b[GENM];
int p[GENM], c[MAX], a[MAX], n, pnum, y, ans;
vector<int> g;
vector<pair<int, int> > gg;
int fp(int x, int y) {
  int res = 1;
  for (; y; y >>= 1, x = 1ll * x * x % M)
    if (y & 1) res = 1ll * res * x % M;
  return res;
}
inline void add(int x, int y) {
  for (; x <= a[n]; x += x & -x) c[x] += y;
}
inline int ask(int x) {
  int res = 0;
  for (; x; x ^= x & -x) res += c[x];
  return res;
}
void prework(int limited) {
  for (int i = 2; i < limited; i++) {
    if (!b[i]) p[pnum++] = i;
    for (int j = 0; j < pnum && 1ll * i * p[j] < limited; j++) {
      b[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
}
void dfs(int x) {
  int t = y;
  if (x == gg.size()) {
    g.push_back(y);
    return;
  }
  for (int i = 0; i <= gg[x].second; i++) {
    dfs(x + 1);
    y *= gg[x].first;
  }
  y = t;
}
void fen_jie(int x) {
  g.clear();
  gg.clear();
  for (int j = 0; j < pnum && p[j] <= x; j++) {
    int res = 0;
    while (x % p[j] == 0) x /= p[j], res++;
    if (res) gg.push_back(make_pair(p[j], res));
  }
  if (x > 1) gg.push_back(make_pair(x, 1));
  y = 1;
  dfs(0);
  sort(g.begin(), g.end());
}
int main() {
  prework(GENM);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) add(a[i], 1);
  for (int j = a[n], pos = n; j >= 1; j--) {
    while (a[pos] >= j) add(a[pos--], -1);
    int big_equal = n - pos, res, la = 0;
    fen_jie(j);
    res = (fp(g.size(), big_equal) - fp(g.size() - 1, big_equal) + M) % M;
    for (int i = 1; i < g.size(); i++) {
      int now = ask(g[i] - 1);
      res = 1ll * res * fp(i, now - la) % M;
      la = now;
    }
    (ans += res) %= M;
  }
  cout << ans;
}
