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 N = 1e5 + 10, mod = 1e9 + 7;
  int prime[N], phi[N], a[N], n, cnt;
  int sum[N], m;
  bool st[N];
  vector<int> fac[N];
  inline int add(int x, int y) { return x + y < mod ? x + y : x + y - mod; }
  inline int sub(int x, int y) { return x >= y ? x - y : x - y + mod; }
  void init() {
    phi[1] = 1;
    for (int i = 2; i < N; i++) {
      if (!st[i]) {
        prime[++cnt] = i;
        phi[i] = i - 1;
      }
      for (int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {
        st[i * prime[j]] = 1;
        if (i % prime[j] == 0) {
          phi[i * prime[j]] = phi[i] * prime[j];
          break;
        }
        phi[i * prime[j]] = phi[i] * (prime[j] - 1);
      }
    }
    for (int i = 1; i < N; i++) {
      for (int j = i; j < N; j += i) {
        fac[j].push_back(i);
      }
    }
  }
  int f(int n, int T) {
    int ans = 0;
    for (int i = T; i <= n; i += T) {
      for (auto it : fac[a[i]]) {
        ans = sub(ans, 1ll * phi[it] * sum[it] % mod * sum[it] % mod);
        sum[it]++;
        ans = add(ans, 1ll * phi[it] * sum[it] % mod * sum[it] % mod);
      }
    }
    for (int i = T; i <= n; i += T) {
      for (auto it : fac[a[i]]) {
        sum[it]--;
      }
    }
    return ans;
  }
  int main() {
    init();
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    int ans = 0;
    for (int T = 1; T <= n; T++) {
      ans = add(ans, 1ll * phi[T] * f(n, T) % mod);
    }
    printf("%d\n", ans);
    return 0;
  }
  