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 + 43;
  bool isp[MAXN];
  int phi[MAXN];
  long long mod = 1e9 + 7;
  long long add(long long a, long long b) { return (a + b) % mod; }
  long long ml(long long a, long long b) { return (a * b) % mod; }
  long long cnt[MAXN];
  bool usd[MAXN];
  vector<int> divs[MAXN];
  void solve() {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
      int curr;
      cin >> curr;
      v.push_back(curr);
    }
    phi[1] = 1;
    for (int i = 2; i < MAXN; ++i) {
      isp[i] = true;
      phi[i] = i;
    }
    for (int i = 1; i < MAXN; ++i) {
      for (int j = i; j < MAXN; j += i) divs[j].push_back(i);
      if (!isp[i]) continue;
      for (int j = i; j < MAXN; j += i) {
        isp[j] = false;
        phi[j] /= i;
        phi[j] *= i - 1;
      }
      isp[i] = true;
    }
    long long sm = 0;
    for (int i = 1; i <= n; ++i) {
      long long crr = 0;
      for (int j = i - 1; j < n; j += i) {
        for (auto e : divs[v[j]]) {
          cnt[e]++;
        }
      }
      for (int j = i - 1; j < n; j += i) {
        long long sm2 = 0;
        for (auto e : divs[v[j]]) {
          if (usd[e]) continue;
          sm2 = add(sm2, ml(phi[e], ml(cnt[e], cnt[e])));
          usd[e] = true;
        }
        crr = add(crr, sm2);
      }
      for (int j = i - 1; j < n; j += i) {
        for (auto e : divs[v[j]]) {
          cnt[e] = 0;
          usd[e] = false;
        }
      }
      sm = add(sm, ml(crr, phi[i]));
    }
    cout << sm << "\n";
  }
  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    solve();
    return 0;
  }
  