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 MAX = 1e5 + 10;
  const long long mod = 1e9 + 7;
  vector<int> G[MAX], s[MAX], p;
  int a[MAX], phi[MAX], cnt[MAX];
  long long res[MAX];
  bool vis[MAX];
  void init() {
    for (int i = 1; i < MAX; i++) {
      for (int j = i; j < MAX; j += i) {
        G[j].push_back(i);
      }
    }
    phi[1] = 1;
    for (int i = 2; i < MAX; i++) {
      if (!vis[i]) {
        p.push_back(i);
        phi[i] = i - 1;
      }
      for (unsigned j = 0; j < p.size() && i * p[j] < MAX; j++) {
        vis[i * p[j]] = true;
        if (i % p[j] == 0) {
          phi[i * p[j]] = phi[i] * p[j];
          break;
        } else {
          phi[i * p[j]] = phi[i] * (p[j] - 1);
        }
      }
    }
  }
  int main() {
    init();
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= n; j += i) {
        s[i].push_back(a[j]);
      }
    }
    for (int i = 1; i <= n; i++) {
      memset(cnt, 0, sizeof(cnt));
      for (unsigned j = 0; j < s[i].size(); j++) {
        int x = s[i][j];
        for (unsigned k = 0; k < G[x].size(); k++) {
          int t = G[x][k];
          res[i] = (res[i] + 1LL * (2 * cnt[t] + 1) * phi[t] % mod) % mod;
          cnt[t]++;
        }
      }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      ans = (ans + res[i] * phi[i] % mod) % mod;
    }
    printf("%lld\n", ans);
    return 0;
  }
  