Bacteria
Time limit1sMemory limit1024 MB
Each adult produces one young per second while young mature into adults; find the total population after T seconds modulo K, given initial counts.
- Level
Medium6 of 10
- Topics
- Math, Combinatorics, Dynamic programming, Number theory
- Solved
- No attempts yet
Problem
Juku forgot to brush his teeth in the evening, and bacteria began multiplying in his mouth. Each bacterium is either young or adult. Every second, each adult produces one new young bacterium, and a newly born young bacterium becomes an adult during the next second. No bacterium ever dies.
If there are initially young and adult bacteria, find how many bacteria (young and adult combined) are in Juku's mouth after seconds. Instead of the actual count, output the remainder when it is divided by the given number .
Input
A single line contains four space-separated integers , , , and (, , , ).
Output
Output the value on a single line, where is the total number of bacteria in Juku's mouth after seconds and "" denotes the remainder of the division.