Practice Maximum Number That Sum of the Prices Is Less Than or Equal to K
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Maximum Number That Sum of the Prices Is Less Than or Equal to K
Problem Statement
You are given an integer k and an integer x. The price of a number num is calculated by the count of set bits at positions x, 2x, 3x, etc., in its binary representation, starting from the least significant bit. The following table contains examples of how price is calculated. The accumulated price of num is the total price of numbers from 1 to num. num is considered cheap if its accumulated price is less than or equal to k. Return the greatest cheap number.
Source: Maximum Number That Sum of the Prices Is Less Than or Equal to K on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
k = 9, x = 1
6
# Example 2
k = 7, x = 2
9
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Number That Sum of the Prices Is Less Than or Equal to K.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.