Explosive Breeding

Problem #425

Tags: mathematics simple

Who solved this?

No translations... yet

MUD's rats reproduce fast! They reach sexual maturity in 35 days and give birth to 14 pups every 21 days. If you took one newborn rat home with you, how many rats would you have after 98 days?

Such a riddle is encountered in MUD1 - probably the oldest game of "multi-user dungeon" type (a kind of text quest) which is still playable, particularly at british-legends.com.

Not regarding the answer to the original puzzle, let's capitalize on it, turning it into general programming problem (supposing these rats reproduce in "vegetative" manner, just like gremlins)...

Input data consist of 4 numbers:

For example if we, given M=35, P=21, N=14 would observe them for D=70 days, it is easy to find that on day 35 we found ourselves lucky owners of 15 rats instead of single one, situation worsens on day 56 when they become 29 in number but real feast comes on day 70 when the 3-rd generation comes, bringing total to 225.

Answer is expected to contain a single value - total amount of rats at the last day of experiment.

Example

input:
35 21 14 98

answer:
645
You need to login to get test data and submit solution.