#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, L = 20, MOD = 1e9 + 7, P = 727, SQ = sqrt(N);
const long long inf = 1e18 + 10, M = 4e2 + 10;
vector<int> v[N];
long long bm[N], a[N], ex[N];
int pw(int c, int d) {
  if (d == 0) return 1;
  int tmp = pw(c, d / 2);
  tmp = 1ll * tmp * tmp % MOD;
  if (d % 2) tmp = 1ll * tmp * c % MOD;
  return tmp;
}
int main() {
  long long n, mx = 0, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ex[a[i]]++, mx = max(mx, a[i]);
  }
  bm[1] = n;
  for (int i = 2; i <= mx; i++) {
    bm[i] = bm[i - 1] - ex[i - 1];
  }
  for (int i = 1; i <= mx; i++)
    for (int j = i; j <= mx; j += i) v[j].push_back(i);
  for (int i = 1; i <= mx; i++) {
    long long ret = 1, cnt = n, res = 0;
    for (int j = 0; j < (int)v[i].size(); j++) {
      long long dif = cnt - bm[v[i][j]];
      if (dif > 0) ret = 1ll * ret * pw(res, dif) % MOD;
      cnt = bm[v[i][j]], res++;
    }
    long long op = 1ll * ret * pw(res, cnt) % MOD;
    ret = 1ll * ret * pw(res - 1, cnt) % MOD;
    ans = (ans + (op - ret) + MOD) % MOD;
  }
  return cout << ans, 0;
}
