Singham and his need for money

https://hack.codingblocks.com/app/practice/1/642/problem
this is the question.


this is my attempt.
it is passing just one test case, other four are failing.

Hey @Sakshi_Suman
Your logic is incorrect please read thequestion again
We have to find min cash whch we will ask from prateek bhaiya ,also our father doubles the amount at end of day,we can use as many days as we want.

So say we want to make 5rs
So on 1st day we ask 1 and it doubles so becomes 2
next day we don’t ask anything so becomes double 4
next day we ask for 1 rs becomes 5 so we stop
So we have to ask for only 2 rs

Here is the code segment for this :slight_smile:

  long long x;
	 cin>>x; //input out number
		int count=0; //to keep count of cash we will ask
		while(x!=0){
			if(x%2==1){  //if money is odd then that means we have to ask for 1Rs
				count++; //incrementing money asked
				x--; //reducing 1 from total money as we borrowed that
			}
			x=x/2; //father doubles the money so required becomes x/2
		}
		cout<<count<<endl;