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;
  using i64 = long long;
  const i64 MOD = 1e9 + 7;
  const int MX = 1e5 + 6;
  vector<int> ph(MX);
  vector<int> d[MX];
  void get_phi() {
    for (int i = 0; i < MX; ++i) {
      ph[i] = i;
    }
    for (int i = 2; i < MX; ++i) {
      if (ph[i] == i)
        for (int j = i; j < MX; j += i) {
          ph[j] -= ph[j] / i;
        }
    }
  }
  void get_divisor() {
    for (int i = 1; i < MX; ++i) {
      for (int j = i; j < MX; j += i) {
        d[j].push_back(i);
      }
    }
  }
  int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    get_phi();
    get_divisor();
    int n;
    cin >> n;
    vector<i64> a(n + 1);
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    i64 ans = 0;
    vector<int> cnt(MX);
    for (int i = 1; i <= n; ++i) {
      i64 s1 = 0;
      for (int j = i; j <= n; j += i) {
        for (int e : d[a[j]]) {
          ++cnt[e];
        }
      }
      for (int j = i; j <= n; j += i) {
        for (int e : d[a[j]]) {
          if (cnt[e]) {
            i64 s2 = cnt[e];
            cnt[e] = 0;
            s2 *= s2;
            s2 %= MOD;
            s2 *= ph[e];
            s2 %= MOD;
            s1 += s2;
            s1 %= MOD;
          }
        }
      }
      ans += ph[i] * s1;
      ans %= MOD;
    }
    cout << ans;
    return 0;
  }
  