#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 10, MD = 1e9 + 7;
long long n, m, a[MX], ans, tmp, mx, cnt[MX];
vector<long long> divisor;
long long Pow(long long a, long long b) {
  if (b == 0) return 1;
  long long tmp = Pow(a, b / 2);
  tmp = tmp * tmp % MD;
  if (b & 1) tmp = tmp * a % MD;
  return tmp;
}
void divisors(int a) {
  divisor.clear();
  for (int i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      divisor.push_back(i);
      if (i * i != a) {
        divisor.push_back(a / i);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> a[1];
  cnt[a[1]]++;
  mx = a[1];
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    mx = max(a[i], mx);
  }
  for (int i = 1; i < MX; i++) {
    cnt[i] += cnt[i - 1];
  }
  for (int i = 1; i <= mx; i++) {
    divisors(i);
    sort(divisor.begin(), divisor.end());
    tmp = 1;
    int k = divisor.size();
    for (int j = 1; j < k; j++) {
      tmp = tmp * Pow(j, cnt[divisor[j] - 1] - cnt[divisor[j - 1] - 1]) % MD;
    }
    tmp = tmp * Pow(k, cnt[mx] - cnt[divisor[k - 1] - 1]) % MD -
          tmp * Pow(k - 1, cnt[mx] - cnt[divisor[k - 1] - 1]) % MD;
    tmp = (tmp + MD) % MD;
    ans += tmp;
    ans = ans % MD;
  }
  cout << ans;
}
