Given a number, you have to represent this number as sum of minimum number of possible psuedobinary numbers. A number is said to be psuedobinary number if its decimal number consists of only two digits (0 and 1). Example: 11,10,101 are all psuedobinary numbers.
Input : 44 Output : 11 11 11 11 Explanation : 44 can be represented as sum of minimum 4 psuedobinary numbers as 11+11+11+11 Input : 31 Output : 11 10 10 Explanation : 31 can be represented as sum of minimum 3 psuedobinary numbers as 11+10+10
The idea to do this is to first observe carefully that we need to calculate minimum number of possible psuedobinary numbers. To do this we find a new number m such that if for a place in given number n, the digit is non-zero then the digit in that place in m is 1 otherwise zero. For example if n = 5102, then m will be 1101. Then we will print this number m and subtract m from n. We will keep repeating these steps until n is greater than zero.
11 10 10
Time Complexity : O( log n )
Auxiliary Space : O(1)
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Represent the given number as the sum of two composite numbers
- Represent a number as the sum of positive numbers ending with 9
- Minimum number of given powers of 2 required to represent a number
- Minimum count of numbers required from given array to represent S
- Number of distinct ways to represent a number as sum of K unique primes
- Represent K^N as the sum of exactly N numbers
- Represent N as sum of K odd numbers with repetitions allowed
- Represent N as sum of K even numbers
- Represent N as sum of K even or K odd numbers with repetitions allowed
- Represent K as sum of N-bonacci numbers
- Represent a given set of points by the best possible straight line
- Minimum possible value T such that at most D Partitions of the Array having at most sum T is possible
- Count of ways to represent N as sum of a prime number and twice of a square
- Represent the fraction of two numbers in the string format
- Sort numbers based on count of letters required to represent them in words
- Represent n as the sum of exactly k powers of two | Set 2
- Represent (2 / N) as the sum of three distinct positive integers of the form (1 / m)
- Add two integers of different base and represent sum in smaller base of the two
- Minimum LCM and GCD possible among all possible sub-arrays
- Maximum number of distinct positive integers that can be used to represent N