#C410. Insect Population Growth
Insect Population Growth
Insect Population Growth
You are given the initial populations of a species of insects for the first two months, denoted as P0
and P1
. For each subsequent month n (with n ≥ 3), the population is the sum of the populations from the two previous months. Formally, the recurrence relation is given by:
\( P(n) = P(n-2) + P(n-1) \) for \( n \geq 3 \)
Your task is to compute the insect population at month N
.
inputFormat
The input consists of a single line containing three space-separated integers:
N
: the number of monthsP0
: the population at month 1P1
: the population at month 2
Constraints: N
will be at least 1. For N = 1
or N = 2
, the answer is P0
or P1
respectively.
outputFormat
Output a single integer representing the insect population at month N
.
5 3 5
21