Problem C
Exponential Eggs
In Elmspring, they celebrate New Year’s Eve with a very local tradition: Eating an egg. Every member of the village receives an egg, and only when the clock strikes 12, you are allowed to eat it.
Of course, using normal chicken eggs would be too easy, so they have opted to give everyone an egg from the legendary roc. Because Elmspring needs so many eggs from such a rare bird, they have decided to tame and breed rocs to ensure every villager will get an egg on New Year’s Eve.
The mayor Eldra Willowbrook wants to ensure they have a healthy surplus, and has decided that they will hatch every egg they don’t use during the festivities. For example, if they get $100$ eggs and only need $77$, then they will hatch the remaining $23$ eggs into rocs.
Now, the roc is not a legendary bird just because it is big: It is also immortal, and every female bird will lay an egg just before New Year’s Eve. Of course, not every hatched roc will be female, only about $f$ of all hatched eggs will be.
Eldra wants to estimate the number of rocs they will have after $N$ years. Since there’s uncertainty involved, she’s fine with an approximation, and has decided to use the formula
\[ R_ n = \lfloor (1 + f)R_{n-1}\rfloor - V \]where $R_ n$ is the number of estimated rocs in year $n$, $V$ is the number of villagers, and $\lfloor n \rfloor $ is the floor of $n$ ($n$ rounded down to the closest integer).
Unfortunately, she doesn’t have a computer available, so she cannot easily compute this for herself. Therefore she has turned to you, as you are the only villager in Elmspring with a computer.
Input
The input consists of one line with three integers $N$, $R_0$ and $V$, and one real number $f$.
$N$ is the number of years to compute for, $R_0$ is the current population of rocs, $V$ is the number of villagers, and $f$ is the approximate proportion of rocs that are female.
Output
Assuming the number of villagers is constant for the next $N$ years, output $R_ N$.
Limits
-
$0 < N \leq 20$
-
$20 \leq R_0 \leq 1000$
-
$0 < V < \lfloor R_0\times f\rfloor $
-
$0.00 < f < 1.00$
-
All real numbers will have exactly two digits after the decimal point.
Sample Explanation
In the first sample, $R_1$ is computed as follows:
\[ R_1 = \lfloor (1 + f)R_{0}\rfloor - V = \lfloor (1 + 0.23)30\rfloor - 5 = 31 \]With $R_1$, we can compute $R_2$:
\[ R_2 = \lfloor (1 + f)R_{1}\rfloor - V = \lfloor (1 + 0.23)31\rfloor - 5 = 33 \]Sample Input 1 | Sample Output 1 |
---|---|
2 30 5 0.23 |
33 |
Sample Input 2 | Sample Output 2 |
---|---|
10 250 100 0.50 |
3068 |