func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, k, n1, ans, m, per1, per2, add;   const int maxn = 1000007;   long long tree[maxn * 4][4];   void build() {     for (int j = n1 - 1; j < n1 + n - 1; j++) {       tree[j][0] = j - n1 + 2;       tree[j][1] = j - n1 + 2;       tree[j][2] = 0;       tree[j][3] = 0;     }     for (int j = n1 + n - 1; j < 2 * n1 - 1; j++) {       tree[j][0] = j - n1 + 2;       tree[j][1] = j - n1 + 2;       tree[j][2] = 0;       tree[j][3] = 0;     }     for (int j = n1 - 2; j > -1; j -= 1) {       tree[j][0] = tree[j * 2 + 1][0];       tree[j][1] = tree[j * 2 + 2][1];       tree[j][2] = 0;       tree[j][3] = 0;     }   }   void push(int node) {     tree[2 * node + 1][3] += tree[node][3];     tree[2 * node + 2][3] += tree[node][3];     tree[node][3] = 0;   }   void update(int node, int a, int b, int val) {     int l, r;     l = tree[node][0];     r = tree[node][1];     if (l == a and r == b) {       tree[node][3] += val;     } else if (r >= a and b >= l) {       push(node);       update(2 * node + 1, a, min(b, (l + r) / 2), val);       update(2 * node + 2, max(a, (l + r) / 2 + 1), b, val);       tree[node][2] = (tree[node * 2 + 1][2] + tree[node * 2 + 1][3] +                        tree[node * 2 + 2][2] + tree[node * 2 + 2][3]);     }   }   int query(int node, int a, int b) {     int l, r;     l = tree[node][0];     r = tree[node][1];     if (r < a || b < l) {       return 0;     }     if (l == a && r == b) {       return tree[node][2] + tree[node][3];     }     push(node);     ans = (query(node * 2 + 1, a, min(b, (l + r) / 2)) +            query(node * 2 + 2, max(a, (l + r) / 2 + 1), b));     tree[node][2] = (tree[2 * node + 1][2] + tree[2 * node + 1][3] +                      tree[2 * node + 2][2] + tree[2 * node + 2][3]);     return ans;   }   int main() {     cin >> n >> k;     n1 = pow(2, ceil(log2(n)));     ;     build();     long long answer = 1;     int now = 1;     for (int j = 0; j < n; j++) {       update(0, now, now, 1);       per1 = 0;       per2 = 0;       if (now + k > n) {         if (k - 1 <= (n - 2) / 2) {           if (now != n) {             per2 = query(0, now + 1, n);           }           if (now + k - n >= 2) {             per1 = query(0, 1, now + k - 1 - n);           }           answer += (1 + per1 + per2);         } else {           answer += (query(0, now + 1 + k - n, now - 1) + 1);         }         now = now + k - n;       } else {         if (k - 1 <= (n - 2) / 2)           answer += (query(0, now + 1, now + k - 1) + 1);         else {           if (now + k != n) {             per2 = query(0, now + k + 1, n);           }           if (now >= 2) {             per1 = query(0, 1, now - 1);           }           answer += (1 + per1 + per2);         }         now += k;       }       cout << answer <<    ;       update(0, now, now, 1);     }     return 0;   }   