Link to the problem is… http://codeforces.com/contest/588/problem/C

# How to solve this codeforces problem?

Take a look at this

https://discuss.codechef.com/questions/76409/can-anyone-explain-logic-to-solve-this

in this question if u sum all the numbers then a number will formed that has x no of digits =1 set bits means that ans=x…

but the problem is no which we get after sum of all the no can be very large beacuse 2^(n) n can be 10000…

so what we are going to do is this we make a array

arr[100000]={0};

ex–the pow of 2’s are—>3,3,5

if no is 2^(3) we will set the arr[3]++; -->arr[3]=1;

if this no again comes arr[3]++ ;----->arr[3]=2 means 2^(3) comes two times…

now 2^(5) arr[5]++;

now we have array 1-index based 0 0 2 0 1

now see here if u have 2^(3) two times u can repersent it 2.(2^(3))—>2^(4)

if arr* is even

then: arr[i+1]+=arr*/2;

arr*=0;

now think othe thing if arr* is odd

means 2^(3) three times sum is 3.2^(3)—>2.2^(3)+2^(3)—>2^(4)+2^(3) ;

means current bit is also set and increse next bit value to arr*/2;

now we can say that

if arr* is odd

then:: arr[i+1]+=arr*/2;

arr*=1;

we are doing a simple work repersenting the binary number manually

at last in our array each value of array either have 0 or 1 no other value ,means we have succcessfully repersented the sum of powers of two(as in question) as a array from left to right

so simply calculte number of set value of the array :: arr*==1;

thats our ans==…

now u can done the example by yourself this is the main hurdle in this question that

how to repersent large sum of the numbers which is in form of 2^(x)…

i have put my best here…i guess u will definetly understand this …

happy to help…if u find any difficulty although.

got the idea thanks