description: Mr. Chanek has an array a of n integers. The prettiness value of a is denoted as:
  
  $$$∑_{i=1}^{n} {∑_{j=1}^{n} {\gcd(a_i, a_j) ⋅ \gcd(i, j)}}$$$
  
  where \gcd(x, y) denotes the greatest common divisor (GCD) of integers x and y.
  
  In other words, the prettiness value of an array a is the total sum of \gcd(a_i, a_j) ⋅ \gcd(i, j) for all pairs (i, j).
  
  Help Mr. Chanek find the prettiness value of a, and output the result modulo 10^9 + 7!
  
  Input
  
  The first line contains an integer n (2 ≤ n ≤ 10^5).
  
  The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5).
  
  Output
  
  Output an integer denoting the prettiness value of a modulo 10^9 + 7.
  
  Example
  
  Input
  
  
  5
  3 6 2 1 4
  
  
  Output
  
  
  77
solution: #include <bits/stdc++.h>
  using namespace std;
  const int maxn = 1e5 + 5;
  const int mod = 1e9 + 7;
  vector<int> divv[maxn];
  void init() {
    for (int i = 1; i < maxn; ++i) {
      for (int j = i; j < maxn; j += i) {
        divv[j].push_back(i);
      }
    }
  }
  vector<int> usedPos;
  bool vis[maxn];
  long long gg[maxn], countt[maxn];
  void clear() {
    for (int v : usedPos) {
      vis[v] = false;
      countt[v] = 0;
      gg[v] = 0;
    }
    usedPos.clear();
  }
  void update(int val, int cnt) {
    for (int v : divv[val]) {
      countt[v] += cnt;
      if (!vis[v]) {
        vis[v] = true;
        usedPos.push_back(v);
      }
    }
  }
  long long getans() {
    sort(usedPos.begin(), usedPos.end());
    for (int pos : usedPos) {
      gg[pos] = (long long)countt[pos] * countt[pos];
    }
    reverse(usedPos.begin(), usedPos.end());
    long long ans = 0;
    for (int pos : usedPos) {
      ans += (long long)pos * gg[pos] % mod;
      for (int npos : divv[pos]) {
        gg[npos] -= gg[pos];
      }
    }
    return ans % mod;
  }
  long long getv(vector<int>& vals) {
    sort(vals.begin(), vals.end());
    int sz = vals.size();
    for (int i = 0, j = 0; i < sz; i = j) {
      int cnt = 0;
      while (j < sz && vals[i] == vals[j]) {
        ++cnt;
        ++j;
      }
      update(vals[i], cnt);
    }
    long long ret = getans();
    clear();
    return ret;
  }
  int a[maxn];
  long long f[maxn];
  vector<int> tmp;
  int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    init();
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
      tmp.clear();
      for (int j = i; j <= n; j += i) {
        tmp.push_back(a[j]);
      }
      f[i] = getv(tmp) % mod;
    }
    long long ans = 0;
    for (int i = n; i; --i) {
      for (int j = i + i; j <= n; j += i) {
        f[i] -= f[j];
      }
      f[i] %= mod;
      f[i] = (f[i] + mod) % mod;
      ans += (long long)f[i] * i % mod;
    }
    ans %= mod;
    cout << ans << endl;
    return 0;
  }
  