#3007
Maximum Number That Sum of the Prices Is Less Than or Equal to K
expert · 1055 · lc medium +32 · 38.5% accepted · 343 likes · top 17%
Description
You are given an integer k and an integer x. The price of a number num is the count of set bits at positions x, 2x, 3x, etc. in its binary representation (starting from the least significant bit).
The accumulated price of num is the sum of prices of all integers from 1 to num. A number num is cheap if its accumulated price is at most k.
Return the greatest cheap number.
Code
1
2
3