Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number Whose Price Sum Is at Most K

Try to solve the Maximum Number That Sum of the Prices Is Less Than or Equal to K problem.

Statement

You are given two integers, k and x.

The price of a positive integer num is defined as the number of set bits (bits with value 11) in its binary representation at 11 based indices from the right (least significant bit) that are multiples of x. That is, a bit at position ii (11 indexed from the right) contributes to the price of num if and only if i(modx)=0i \pmod x = 0 and the ii-th bit is 11.

Return the maximum integer num such that the sum of the prices of all integers from 11 to num is less than or equal to k.

Constraints:

  • 1≤1 \leq k ≤1015\leq 10^{15}

  • 1≤1 \leq x ≤8\leq 8

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number Whose Price Sum Is at Most K

Try to solve the Maximum Number That Sum of the Prices Is Less Than or Equal to K problem.

Statement

You are given two integers, k and x.

The price of a positive integer num is defined as the number of set bits (bits with value 11) in its binary representation at 11 based indices from the right (least significant bit) that are multiples of x. That is, a bit at position ii (11 indexed from the right) contributes to the price of num if and only if i(modx)=0i \pmod x = 0 and the ii-th bit is 11.

Return the maximum integer num such that the sum of the prices of all integers from 11 to num is less than or equal to k.

Constraints:

  • 1≤1 \leq k ≤1015\leq 10^{15}

  • 1≤1 \leq x ≤8\leq 8