a very easy problem

EASYPROB Problem - CodeChef plz explain the question

@code_baba:

The problem asks you to output some form of these numbers: 137, 1315, 73, 136, 255, 1384, 16385, one per line in the listed order.

Let’s see the first line of the correct output:

137=2(2(2)+2+2(0))+2(2+2(0))+2(0)

Hmmm… I don’t want to take the fun out the problem by giving the answer directly to you. So, I will give you a clue.

The clue:

If you have been thinking in this direction :

“How can I make the left hand side (in this case 137) to become the right hand side?”

Stop thinking!

The right direction to think for this problem is:

“How can I make the RIGHT HAND SIDE of the equation to become the left hand side?”

Got it?

Just notice the number being used again and again and you will be able to find the pattern.(Did you know :2^2=4)

5 Likes

Hi

In this problem you have to represent the given number in form of sum if 2^n where n>=0

for example

5=4+1=(2^2)+(2^0)

For 1-10

0=0

1=2(0)

2=2

3=2+2(0)

4=2(2)

5=2(2)+2(0)

6=2(2)+2

7=2(2)+2+2(0)

8=2(2+2(0))

9=2(2+2(0))+2(0)

10=2(2+2(0))+2

12=2(2+2(0))+2(2)

What!!! wait guys, don’t confuse me please

Hint:

137 = 128 + 8 + 1

1315 = 1024 + 256 + 32 + 2 + 1

73 = 64 + 8 + 1

136 = 128 + 8

255 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1

1384 = 1024 + 256 + 64 + 32 + 8

16385 = 16384 + 1

Every number can be written as sum of powers of 2 with each power used only once or never

1 Like

I believe that this problem could just be solved by using printf function, the rest is upto you for finding :slight_smile: