Half
InterviewTime limit2sMemory limit512 MB
Starting with n apples and meeting k friends, each friend either takes half an apple or half of the current amount; list every possible final amount.
- Level
Medium5 of 10
- Topics
- Implementation, Brute force, Math, Sorting
- Solved
- No attempts yet
Problem
Kind-hearted Daniil has several apples. Because of his natural kindness, every time he meets one of his friends, he looks at the apples he has and gives the friend half of them.
Daniil does not like all his friends equally, so to some of them he gives half an apple, and to others he gives half of the apples he has. Daniil's eye for measurement is not as good as his generosity, and he cannot divide apples into more than two parts. Therefore, if he meets a friend and has a non-integer number of apples, he has to give half an apple.
In the morning Daniil had apples, and during the day he met friends. Find out how many apples he could have left in the evening.
Input
The input file contains two integers: , the number of apples Daniil has, and , the number of friends he met during the day (, ).
Output
The first line of the output file must contain the number of possible answers to the question of how many apples Daniil can have in the evening. The next line must contain the real numbers, sorted in ascending order, that are the possible answers.