3007. Maximum Number That Sum of the Prices Is Less Than or Equal to K
You are given an integer
k
and an integerx
.Consider
s
is the 1-indexed binary representation of an integernum
. The price of a numbernum
is the number ofi
‘s such thati % x == 0
ands[i]
is a set bit.Return the greatest integer
num
such that the sum of prices of all numbers from1
tonum
is less than or equal tok
.Note:
- In the binary representation of a number set bit is a bit of value
1
.- The binary representation of a number will be indexed from right to left. For example, if
s == 11100
,s[4] == 1
ands[2] == 0
.
c++
1 |
|