#include <bits/stdc++.h>
using namespace std;
auto fio = (ios::sync_with_stdio(0), cin.tie(0), cout.tie(0));
long long fpow(long long x, long long p) {
  long long r = 1;
  for (; p > 0; p >>= 1, x = x * x % 1000000007)
    if (p & 1) r = r * x % 1000000007;
  return r;
}
int32_t main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long m = a.back();
  long long ans = 0;
  vector<vector<long long>> div(m + 1);
  for (long long i = 1; i <= m; i++) {
    long long res = 1;
    div[i].push_back(i);
    for (long long j = 0; j < div[i].size() - 1; j++) {
      long long d = div[i][j];
      long long t = div[i][j + 1];
      long long dpos = lower_bound(a.begin(), a.end(), d) - a.begin();
      long long tpos = lower_bound(a.begin(), a.end(), t) - a.begin();
      if (dpos != tpos) {
        long long r = tpos - dpos;
        res = res * fpow(j + 1, r) % 1000000007;
      }
    }
    long long r = n - (lower_bound(a.begin(), a.end(), i) - a.begin());
    ans += res * (fpow(div[i].size(), r) - fpow(div[i].size() - 1, r)) %
           1000000007;
    ans %= 1000000007;
    for (long long j = i; j <= m; j += i) div[j].push_back(i);
  }
  cout << (ans + 1000000007) % 1000000007 << endl;
}
