Find numbers who compose the sum of sequence numbers(nth root)

149 Views Asked by At

I have an sequence of numbers 1, 2, 4, 8, 16, 32 and so on. Given an number, which must be the sum of the sequence, for example: 44(which is the sum of 4+8+32). How do I know the number 44 is composed by 4, 8 and 32?

I suck at math, and I think most suitable is root extraction(Nth root), someone can give some advice for my problem? If there's any method that can help.

2

There are 2 best solutions below

0
On

This is how you write numbers in binary.

Divide your number by 2, divide the result by 2 again, and repeat.

Now look at your remainders. If a remainder is 0, ignore it. If the remainder of the first division is 1, that gives you 1. If the remainder of the second division is 1, that gives you 2. If the remainder of third division is 1, you get 4; then 8; then 16; and so on.

In your example, $$ 44/2=22\\ 22/2=11\\ 11/2=5 rem 1 \text{(that means 4)}\\ 5/2=2 rem 1 \text{(that means 8)}\\ 2/2=1\\ 1/2=0 rem 1 \text{(that means 32)}$$

0
On

a straightforward approach is to first find the largest number of the sequence not exceeding the given number, in your example this number is $32$, then substract from given number ($44-32=12$) and repeat the process with the diference until no more is left. so for $49$ the process is $$49-32=17$$ $$17-16=1$$ $$1-1=0$$