Time limit
1s
Memory limit
128 MB
A biologist is observing the reproduction of a newly discovered paramecium species. The species reproduces asexually, and on day 0 one newborn individual is placed in a tank.
Each individual behaves according to its age, measured as the number of whole days since it was born.
a, it becomes mature.a and less than b, it produces exactly one newborn. It also produces one on the day it first becomes mature.b, it no longer produces newborns. Therefore, one individual produces exactly b - a newborns during its lifetime.d, it dies and disappears from the tank.After the growth, births, and deaths for each day have been reflected, the individuals still in the tank are counted. Given a, b, d, and N, compute the number of individuals alive on day N.
The first line contains four integers a, b, d, and N, separated by spaces.
0 < a < b < d <= 10,000, 1 <= N <= 1,000,000
Print the number of individuals alive in the tank on day N, modulo 1000.