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 _ = 1e5 + 7, P = 1e9 + 7;
  int N, A[_], prm[_], cprm, phi[_], cnt[_];
  bool nprm[_];
  vector<int> lst[_];
  void sieve() {
    phi[1] = 1;
    for (int i = 2; i <= 1e5; ++i) {
      if (!nprm[i]) {
        prm[++cprm] = i;
        phi[i] = i - 1;
      }
      for (int j = 1; prm[j] * i <= 1e5; ++j) {
        nprm[prm[j] * i] = 1;
        if (i % prm[j] == 0) {
          phi[i * prm[j]] = phi[i] * prm[j];
          break;
        }
        phi[i * prm[j]] = phi[i] * (prm[j] - 1);
      }
    }
    for (int i = 1; i <= 1e5; ++i)
      for (int j = i; j <= 1e5; j += i) lst[j].push_back(i);
  }
  int main() {
    ios::sync_with_stdio(0);
    sieve();
    cin >> N;
    for (int i = 1; i <= N; ++i) cin >> A[i];
    int ans = 0;
    vector<int> vis;
    for (int d = 1; d <= N; ++d) {
      for (int t = d; t <= N; t += d)
        for (auto v : lst[A[t]])
          if (!(cnt[v]++)) vis.push_back(v);
      for (auto t : vis) {
        ans = (ans + 1ll * phi[d] * phi[t] % P * cnt[t] * cnt[t]) % P;
        cnt[t] = 0;
      }
      vis.clear();
    }
    cout << ans;
    return 0;
  }
  