almost 3 years ago

## CodeFights近日感想

Lonerz got some crazy growing plants and he wants to grow them nice and well. Initially, the garden is completely barren. Each morning, lonerz can put any number of plants into the garden to grow. And at night, each plant mutates into two plants. lonerz really hopes to see n plants in his garden.

Your task is to find the minimum number of plants lonerz has to plant to get n plants one day?

Example:
Doubling(5) = 2
Lonerz hopes to see 5 plants. He adds 1 plant on the first morning and on the third morning there would be 4 plants in the garden. He then adds 1 more and sees 5 plants. So, lonerz only needs to add 2 plants to his garden.

Doubling(8) = 1
lonerz hopes to see 8 plants. Thus, he just needs to add 1 plant in the beginning and wait for it to double till 8.

1 -> 1 (第一天種就得到1)
2 -> 10 (第一天種，第二天就得到2)
3 -> 11 (第一天種，第二天再種就得到3)
4 -> 100 (第一天種，第三天就得到4)
5 -> 101 (第一天種，第三天再種就得到5)
6 -> 110 (第一天種，第二天再種，第三天就得到6)
7 -> 111 (第一天種，第二天再種，第三天再種一次就得到7)