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>
  #pragma warning(disable : 4996)
  #pragma comment(linker, "/STACK:16777216")
  using namespace std;
  const int INF = 1000000000 + 1e8;
  const long long LINF = 2000000000000000000;
  const int N = 1e5 + 1010;
  const long long mod = 1e9 + 7;
  int phi[N];
  vector<int> divs[N];
  int cnt[N];
  void calcPhi() {
    phi[0] = 0;
    phi[1] = 1;
    for (int i = 2; i < N; i++) phi[i] = i;
    for (int i = 2; i < N; i++)
      if (phi[i] == i)
        for (int j = i; j < N; j += i) phi[j] -= phi[j] / i;
  }
  void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &to : a) cin >> to;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j * j <= a[i]; j++) {
        if (a[i] % j == 0) {
          divs[i].push_back(j);
          if (j != a[i] / j) {
            divs[i].push_back(a[i] / j);
          }
        }
      }
    }
    calcPhi();
    long long ans = 0;
    long long s = 0;
    for (int x = 1; x <= n; x++) {
      for (int i = x - 1; i < n; i += x) {
        for (int q = 0; q < int(divs[i].size()); q++) {
          cnt[divs[i][q]]++;
        }
      }
      s = 0;
      for (int i = x - 1; i < n; i += x) {
        for (int q = 0; q < int(divs[i].size()); q++) {
          if (cnt[divs[i][q]] > 0) {
            s = (s + 1LL * cnt[divs[i][q]] * cnt[divs[i][q]] * phi[divs[i][q]]);
            s %= mod;
            cnt[divs[i][q]] = 0;
          }
        }
      }
      ans = (ans + phi[x] * s) % mod;
    }
    cout << ans;
  }
  int main() {
    srand(time(0));
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tst = 1;
    while (tst--) {
      solve();
    }
  }
  