#P5775. [AHOI2006] 斐波卡契的兔子

[AHOI2006] 斐波卡契的兔子

Problem Description

Kaka has started raising rabbits. His mother bought him a pair of newborn rabbits. Kaka learned that the rabbits reproduce as follows: a pair of rabbits will give birth for the first time one month after birth, producing aa pairs of rabbits. Then, two months after birth, they will produce bb pairs of rabbits. In the third month and every month after that, they will reproduce cc pairs of rabbits each month (abca \le b \le c). We know from the Fibonacci sequence that rabbits can reproduce very quickly. However, Kaka has as many good friends as rabbits, so he wants to have kk pairs of rabbits after mm months to give them to his friends. Can his wish come true?

[Task] Write a program that reads the input information from the input file; computes how many pairs of rabbits Kaka will have after mm months, denoted as PP; computes the minimum number of pairs of rabbits his mother must buy at the beginning so that Kaka will have at least kk pairs of rabbits after mm months, denoted as QQ; and outputs the results to the output file.

Input Format

The first line of the input file contains four positive integers: aa, bb, cc, and mm. The second line contains only one positive integer kk. Their meanings are described above.

Output Format

Output two lines. The first line contains an integer PP, and the second line contains an integer QQ.

0 1 1 10
10000

89
113

Hint

Constraints: 0abc1000 \le a \le b \le c \le 100, 1m30001 \le m \le 3000, 1k1060001 \le k \le 10^{6000}.

Translated by ChatGPT 5