description: You have an array a consisting of n distinct positive integers, numbered from 1 to n. Define p_k as $$$p_k = ∑_{1 ≤ i, j ≤ k} a_i mod a_j, where x \bmod y denotes the remainder when x is divided by y. You have to find and print p_1, p_2, \ldots, p_n$$$. 
  
  Input
  
  The first line contains n — the length of the array (2 ≤ n ≤ 2 ⋅ 10^5).
  
  The second line contains n space-separated distinct integers a_1, …, a_n (1 ≤ a_i ≤ 3 ⋅ 10^5, a_i ≠ a_j if i ≠ j). 
  
  Output
  
  Print n integers p_1, p_2, …, p_n. 
  
  Examples
  
  Input
  
  
  4
  6 2 7 3
  
  
  Output
  
  
  0 2 12 22
  
  
  Input
  
  
  3
  3 2 1
  
  
  Output
  
  
  0 3 5
solution: #include <bits/stdc++.h>
  using namespace std;
  const int M = 300000;
  long long c[2][M + 10], ans;
  int n;
  void add(long long c[], int x, int y) {
    for (; x <= M; x += x & (-x)) c[x] += y;
  }
  long long get(long long c[], int x) {
    long long s = 0;
    for (; x; x -= x & (-x)) s += c[x];
    return s;
  }
  int main() {
    scanf("%d", &n);
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      ans += 1ll * (i - 1) * x - get(c[0], x);
      ans += sum;
      for (int j = 1; j <= M / x; j++) ans += get(c[1], j * x - 1) * x;
      ans -= 1ll * (i - 1) * x * (M / x);
      add(c[1], x, 1);
      sum += x;
      for (int j = x; j <= M; j += x) add(c[0], j, x);
      printf("%lld%c", ans, " \n"[i == n]);
    }
    return 0;
  }
  