#P5775. Rabbit Reproduction
Rabbit Reproduction
Rabbit Reproduction
Kaka has started raising rabbits! His mother bought him a pair of newborn rabbits. Kaka learned that the reproduction pattern of rabbits is as follows: a pair of newborn rabbits will produce \(a\) pairs after 1 month for the first time, then produce \(b\) pairs in the second month after their birth, and from the third month onward each pair will produce \(c\) pairs (with \(a \le b \le c\)).
Let \(P\) be the total number of rabbit pairs after \(m\) months if Kaka initially starts with 1 pair (i.e. the pair his mother bought him). Also, let \(Q\) be the minimum number of pairs his mother needs to purchase initially so that after \(m\) months Kaka has at least \(k\) pairs of rabbits, which he may then share with his \(k\) friends.
Your task is to write a program that reads the input from a file, computes \(P\) and \(Q\) as defined above, and writes the result to an output file.
Reproduction details:
- A pair of rabbits that has just been born is considered to have age 0.
- At the end of the 1st month (when age becomes 1), a pair produces \(a\) pairs.
- At the end of the 2nd month (age becomes 2), a pair produces \(b\) pairs.
- At the end of the 3rd month and every month afterward (age \(\ge 3\)), a pair produces \(c\) pairs.
Note that reproduction is cumulative; all rabbit pairs, including those newly born, will age and then reproduce in subsequent months following the same rules.
inputFormat
The input consists of a single line containing five integers: \(a\), \(b\), \(c\), \(m\), and \(k\), where:
- \(a, b, c\): numbers of pairs produced by a rabbit pair in the 1st, 2nd, and 3rd (and later) months respectively (with \(a \le b \le c\)).
- \(m\): the number of months.
- \(k\): the desired minimum number of pairs after \(m\) months.
All values are separated by spaces.
outputFormat
The output should contain two integers separated by a space:
- \(P\): the total number of rabbit pairs after \(m\) months starting with 1 pair.
- \(Q\): the minimum number of initial pairs required so that after \(m\) months the total number is at least \(k\).
sample
1 2 3 1 2
2 1