Problem 61083. Express base-10 integers in lazy binary

The binary (or base-2) representations of a number n can be constructed as follows:
Step 1: If n = 0, then the binary representation is 0.
Step 2: If n > 0, then do the following:
a. Add 1 to the least-significant bit of the binary representation of n-1.
b. If any bit is equal to 2, replace that bit with 0 and add 1 to the next most significant bit.
c. Repeat step 2b till all bits are 0 or 1.
For example, the binary representation of 7 is 111. To get the binary representation of 8, we follow the steps to get 112, 120, 200, and the result 1000.
The procedure for determining the lazy binary representation is similar except that step 2c is omitted. That is, we are too lazy to repeat step 2b. Given that the lazy binary representation of 7 is 111, we would follow the modified procedure to get 112 and 120, the lazy binary representation of 8. For n = 9, the steps yield 121 and the result 201, and for n = 10, the steps yield 202 and the result 210.
Notice that in applying step 2b for constructing binary numbers, there will be at most one 2. However, in lazy binary, there could be multiple 2s. Change only the least significant 2, as in the calculation of the lazy binary representation of 10.
Write a function to compute the lazy binary representation of a base-10 integer. Express the result as a 64-bit unsigned integer.

Solution Stats

47.06% Correct | 52.94% Incorrect
Last Solution submitted on Dec 03, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers5

Suggested Problems

More from this Author315

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!