A problem to code

Bob got a task at school to collect ‘N’ stones. Each day he can collect only one stone. As ‘N’ can be a
very large number so it could take many days to complete the task, but then he remembers that his
mother gave him a magic that can double anything (i.e if he has 2 stones, the magic will make them to
4 stones). Bob can use this magic any number of time on the collected stone on a particular day and
add this to the previously collected stones. Remember that he wants exactly ‘N’ stones and he can't
throw any stone. If he gets more than ‘N’ stones then he gets 0 marks, of course he doesn't want 0
marks. Help him to collect exactly ‘N’ stones in minimum number of days.
For Example:
For ‘N’=1 the days = 1
For ‘N’=3 the days = 2
You forgot to ask a question, this isn't a homework site. If you're looking for someone to write the program for you, post in the job section.
So the trick is to find the minimum number of days, figure it out and do it on paper and then code it. I solved it in 5 mins, you can too.
Last edited on
Topic archived. No new replies allowed.