consider a special type of animal known as an ewwok that reproduces following the ru 5150572

Consider a special type of animal known as an Ewwok that reproduces following the rules below:

  • An Ewwok dies six months after it is born. That is, if an Ewwok is born in month 0, it will die in month 6.
  • An Ewwok gives birth to two Ewwoks every two months until it dies. That is, if an Ewwok is born in month 0, it will reproduce in months 2 and 4. It does not reproduce in month 6 or beyond.
  • In each month, among all the Ewwoks that have been alive for exactly three months, there is one that dies. That is, if there are n (n > 0) Ewwoks that are born in month 0, one of them will die in month 3.

Given an integer initial representing the number of Ewwoks born in month 0, and an integer m representing a month, your task in this question is to write a program that calculates and returns the number of Ewwoks alive in month m.

For example, if there is 1 Ewwok born in month 0 (initial = 1):

  • In month 1, there is 1 Ewwok.
  • In month 2, there are 3 Ewwoks (2 are born by the initial Ewwok).
  • In month 3, there are 2 Ewwoks (the initial Ewwok dies).
  • In month 4, there are 6 Ewwoks (4 are born).
  • In month 5, there are 5 Ewwoks (1 of the Ewwoks born in month 2 dies).
  • In month 6, there are 15 Ewwoks (10 are born).
  • In month 7, there are 14 Ewwoks (1 of the Ewwoks born in month 4 dies).
  • In month 8, there are 39 Ewwoks (the remaining Ewwok born in month 2 dies; 26 are born).

You may assume that initial >= 0 and m >= 0.

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now