#P5743. Peach Eating Monkey Problem
Peach Eating Monkey Problem
Peach Eating Monkey Problem
A little monkey bought a certain number of peaches. On the first day, he ate exactly half of the peaches plus one extra. On every subsequent day, he repeated the process by eating half of the remaining peaches plus one extra. On the morning of the n-th day, only one peach was left. Given the number of days n, determine the number of peaches the monkey originally bought.
Note: Formulate your answer using the reverse recurrence relation. If we denote the number of peaches on the morning of day i by ai, then the recurrence relation can be derived in reverse as:
\( a_{i} = 2\,(a_{i+1} + 1) \)
with the base case \( a_{n} = 1 \). Therefore, the solution is given by:
\( a_{1} = 3 \times 2^{n-1} - 2 \)
inputFormat
The input consists of a single integer n (n ≥ 1) on a single line, representing the day on which only one peach remains.
outputFormat
Output a single integer, the number of peaches originally bought by the monkey.
sample
2
4