-->
当前位置:首页 > 题库

PROGRAMMING:Divide candy (circular linear table)

Luz5年前 (2021-05-10)题库381
Xiao Ming takes n kindergarten children to form a circle to share candy. Everyone takes an even number of candy. Each child divides the candy in his hand into two parts and gives one to the next child (if the number is numbered, No.1 to No.2, No.2 to No.3,... No.n to No.1, at this time, the number of candy of No.1 child is half of his own plus half of that of the previous No.1 child), At this time, if a child's candy number is odd, Xiao Ming is responsible for sending one to form an even number. Divide it into two parts and give it to the next child... At last, everyone will have the same amount of candy. If given the number of people and the number of candies on each child's hand, the program will calculate how many candies Xiao Ming will need to reissue at least.
###Input format:
Input two lines of data: the first line is an integer, indicating the number of children; The second line is n even numbers (separated by spaces) indicating the amount of candy each child started with.
###Output format:
Output an integer, indicating the total number of candy Xiao Ming needs to reissue.
###Input example:
```in
three
4 2 2
```
###Output example:
```out
four
```







answer:If there is no answer, please comment