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 maxn = 1e5 + 100;
  const int N = 1e5 + 7;
  const int mod = 1e9 + 7;
  int prim[maxn], pn = 0, vis[maxn], phi[maxn];
  void Phi() {
    for (int i = 2; i <= N; i++) {
      if (!vis[i]) prim[++pn] = i, phi[i] = i - 1;
      for (int j = 1; j <= pn && i * prim[j] <= N; j++) {
        vis[i * prim[j]] = 1;
        if (i % prim[j] == 0) {
          phi[i * prim[j]] = phi[i] * prim[j];
          break;
        } else
          phi[i * prim[j]] = phi[i] * (prim[j] - 1);
      }
    }
  }
  int a[200050];
  long long ans[200050];
  vector<int> fac[200050];
  int sum[200050];
  long long solve(int n, int T) {
    long long ans = 0;
    for (int i = T; i <= n; i += T) {
      for (auto p : fac[a[i]]) {
        ans = (ans - 1ll * phi[p] * sum[p] * sum[p] % mod);
        if (ans < mod) ans += mod;
        sum[p]++;
        ans = (ans + 1ll * phi[p] * sum[p] * sum[p] % mod);
        if (ans > mod) ans -= mod;
      }
    }
    for (int i = T; i <= n; i += T) {
      for (auto p : fac[a[i]]) {
        sum[p]--;
      }
    }
    return ans;
  }
  int main() {
    Phi();
    phi[1] = 1;
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= 100000; ++i) {
      for (int j = i; j <= 100000; j += i) {
        fac[j].push_back(i);
      }
    }
    long long res = 0;
    for (int i = 1; i <= n; ++i) {
      ans[i] = phi[i];
      ans[i] = ans[i] * solve(n, i) % mod;
      res += ans[i];
      if (res > mod) res -= mod;
    }
    printf("%lld", res);
  }
  