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>
  #pragma GCC target("avx2")
  #pragma GCC optimization("O3")
  #pragma GCC optimization("unroll-loops")
  using namespace std;
  const long long MOD = 1000000007;
  const int maxn = 100005;
  vector<int> primes;
  int phicache[maxn];
  int counts[maxn];
  vector<int> divisors[maxn];
  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector<bool> sieve(maxn, 1);
    for (int i = 2; i < maxn; i++) {
      if (sieve[i]) {
        primes.push_back(i);
        int j = 2 * i;
        while (j < maxn) {
          sieve[j] = 0;
          j += i;
        }
      }
    }
    for (int i = 1; i < maxn; i++) {
      counts[i] = 0;
      int j = i;
      while (j < maxn) {
        divisors[j].push_back(i);
        j += i;
      }
    }
    for (int i = 1; i < maxn; i++) {
      phicache[i] = i;
    }
    for (int p : primes) {
      int j = p;
      while (j < maxn) {
        phicache[j] = (p - 1) * (phicache[j] / p);
        j += p;
      }
    }
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    for (int d = 1; d <= n; d++) {
      vector<int> seen;
      for (int j = d - 1; j < n; j += d) {
        for (int div : divisors[a[j]]) {
          if (!counts[div]++) seen.push_back(div);
        }
      }
      for (int div : seen) {
        long long count = counts[div];
        ans += (count * count * phicache[div] * phicache[d]) % MOD;
        counts[div] = 0;
        ans %= MOD;
      }
    }
    cout << ans << endl;
  }
  