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 + 10;
  const int mod = 1e9 + 7;
  int n;
  unordered_map<int, int> mp;
  int phi[maxn];
  vector<int> num1[maxn];
  vector<int> num2;
  int mul(int a, int b, int p) {
    int ans = 0;
    for (; b; b >>= 1, a = (a + a) % p)
      if (b & 1) ans = (ans + a) % p;
    return ans;
  }
  void phi_table(int n) {
    phi[1] = 1;
    for (int i = 2; i <= n; i++)
      if (!phi[i]) {
        for (int j = i; j <= n; j += i) {
          if (!phi[j]) phi[j] = j;
          phi[j] = phi[j] / i * (i - 1);
        }
      }
  }
  void init() {
    phi_table(maxn - 1);
    for (int i = 1; i < maxn; i++) {
      for (int j = i; j < maxn; j += i) {
        num1[j].push_back(i);
      }
    }
    int temp;
    num2.push_back(0);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &temp);
      num2.push_back(temp);
    }
  }
  void solve() {
    int ans = 0;
    for (int d = 1; d <= n; d++) {
      int tmp = 0;
      mp.clear();
      for (int i = 1; i <= n / d; i++) {
        for (auto it : num1[num2[i * d]]) {
          mp[it]++;
        }
      }
      for (auto it : mp) {
        tmp =
            (tmp + mul(phi[it.first], mul(it.second, it.second, mod), mod)) % mod;
      }
      ans = (ans + mul(phi[d], tmp, mod)) % mod;
    }
    printf("%d\n", ans);
  }
  signed main() {
    scanf("%d", &n);
    init();
    solve();
  }
  