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 nmax = 1e5 + 42, mod = 1e9 + 7;
  int n, inp[nmax];
  vector<int> seen[nmax], dvd[nmax];
  int phi[nmax];
  int cnt[nmax];
  long long sum_gcd(vector<int> cur) {
    long long alone = 0;
    for (auto w : cur) alone = (alone + w) % mod;
    long long together = 0;
    for (auto p : cur) {
      for (auto q : dvd[p]) {
        together = (together + 1LL * phi[q] * cnt[q]) % mod;
        cnt[q]++;
      }
    }
    for (auto p : cur) {
      for (auto q : dvd[p]) cnt[q] = 0;
    }
    long long ret = (alone + together * 2) % mod;
    return ret;
  }
  int main() {
    scanf("%i", &n);
    for (int i = 1; i <= n; i++) scanf("%i", &inp[i]);
    for (int i = 1; i < nmax; i++) phi[i] = i;
    for (int i = 2; i < nmax; i++)
      if (phi[i] == i) {
        for (int j = i; j < nmax; j = j + i) phi[j] = phi[j] / i * (i - 1);
      }
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= n; j = j + i) seen[i].push_back(inp[j]);
    }
    for (int i = 1; i < nmax; i++) {
      for (int j = i; j < nmax; j = j + i) dvd[j].push_back(i);
    }
    long long outp = 0;
    for (int i = 1; i <= n; i++)
      outp = (outp + 1LL * phi[i] * sum_gcd(seen[i])) % mod;
    printf("%lld\n", outp);
    return 0;
  }
  