#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
int add(int a, int b) {
  if (a + b >= MOD) return a + b - MOD;
  return a + b;
}
int sub(int a, int b) { return add(a, MOD - b); }
int mul(int a, int b) { return (long long)a * b % MOD; }
int modpow(int b, int p) {
  if (p == 0) return 1;
  int ans = modpow(mul(b, b), p / 2);
  if (p % 2 == 1) ans = mul(ans, b);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), freq((int)1e5 + 1);
  for (int i = 0; i < n; i++) cin >> a[i], freq[a[i]]++;
  for (int i = (int)1e5 - 1; i >= 1; i--) freq[i] += freq[i + 1];
  int ans = 0;
  for (int i = 1; i <= (int)1e5; i++) {
    if (freq[i] == 0) break;
    vector<int> div;
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        div.push_back(j);
        if (j * j != i) div.push_back(i / j);
      }
    }
    sort(div.begin(), div.end());
    int tmp = 1;
    for (int i = 1; i < (int)div.size(); i++)
      tmp = mul(tmp, modpow(i, freq[div[i - 1]] - freq[div[i]]));
    tmp = mul(tmp, modpow((int)div.size(), freq[div.back()]));
    ans = add(ans, tmp);
    if (i > 1) {
      tmp = 1;
      div.pop_back();
      for (int i = 1; i < (int)div.size(); i++)
        tmp = mul(tmp, modpow(i, freq[div[i - 1]] - freq[div[i]]));
      tmp = mul(tmp, modpow((int)div.size(), freq[div.back()]));
      ans = sub(ans, tmp);
    }
  }
  cout << ans << '\n';
  return 0;
}
