#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int powmod(int a, int n) {
  if (n == 0) return 1 % MOD;
  if (n == 1) return a % MOD;
  int ans = powmod(a, n / 2);
  ans = (1LL * ans * ans) % MOD;
  if (n % 2 == 0) return ans;
  return (1LL * ans * a) % MOD;
}
bool solve() {
  int n;
  if (scanf("%d", &n) == EOF) return false;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  vector<int> vs(a.back() + 1);
  int last = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int old_i = i;
    while (i + 1 < n && a[i + 1] == a[i]) i++;
    for (last++; last <= a[i]; ++last) {
      vs[last] = old_i;
      vector<int> divs;
      for (int k = 1; k * k <= last; ++k) {
        if (last % k == 0) {
          divs.push_back(k);
          if (k * k != last) divs.push_back(last / k);
        }
      }
      sort(divs.begin(), divs.end());
      int pp = 1;
      size_t j;
      int old_ws = -1;
      for (j = 0; vs[divs[j]] != vs[last]; ++j) {
        size_t last2 = j;
        while (vs[divs[j + 1]] != vs[last] && vs[divs[j]] == vs[divs[j + 1]])
          j++;
        pp = (1LL * pp * powmod(j + 1, vs[divs[j + 1]] - vs[divs[j]])) % MOD;
      }
      ans = (ans + 1LL * pp *
                       (powmod(divs.size(), n - old_i) + MOD -
                        powmod(divs.size() - 1, n - old_i))) %
            MOD;
    }
    last--;
  }
  printf("%d\n", ans);
  return true;
}
int main() {
  solve();
  return 0;
}
