num is the count of set bits at positions step, 2·step, 3·step, …
For example, 13 = 1101: with step = 1 its tax is 3, with step = 2 it is 1 (only position 4 is set).
The running tax of num is the sum of the taxes of all numbers from 1 to num. Return the largest num whose running tax does not exceed budget.budget=6, step=1 → 4
With step = 1 the tax is the number of ones: 1, 1, 2, 1 for 1–4, totalling 5. Number 5 has a tax of 2, which would push the total to 7 > 6.
budget=3, step=2 → 6
Only bit 2 (weight 2) is taxed. The taxes of 1–7 are 0, 1, 1, 0, 0, 1, 1, so the total through 6 is 3, and including 7 it is 4.
budget=6, step=1
4
Run checks the first 3 tests in your browser. Submit checks all 128 tests on the server, hidden ones included.