LL n, k, m; LL calc(LL q){ if (k == 1) return n-q; LL ans = 0, l = q, r = q; while (l < n) { ans += min(r, n-1)-l+1; l = l*k+1; r = r*k+k; } return ans; }
voidsolve(){ cin >> n >> k >> m; while (m--) { LL q; cin >> q; cout << calc(q) << '\n'; } }
int tag1[MAXN], tag2[MAXN], cnt[MAXM]; voidsolve(){ int n, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { int op, x; cin >> op >> x; if (op == 1) tag1[x]++; elseif (op == 2) tag1[1]++, tag1[x]--; elseif (op == 3) tag2[x]++; elseif (op == 4) tag2[x]--, tag1[1]++; } for (int i = 1; i <= n; ++i) tag1[i] += tag1[i>>1]; for (int i = n; i >= 1; --i) tag2[i>>1] += tag2[i]; for (int i = 1; i <= n; ++i) cnt[tag1[i]+tag2[i]]++; for (int i = 0; i <= m; ++i) cout << cnt[i] << ' '; }