eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Mosquito Multiplication

Mosquito Multiplication

\includegraphics{https://static.e-olymp.com/content/88/88ab6423a5451b03dbbc1411b0d3df94bb628ff9.jpg} Have you ever wondered why there are so many mosquitos in wet environments? One of the reasons is that adult female mosquitos can lay as many as hundreds of eggs. Even if most of them do not (fortunately!) survive, it is said that a single pair of mosquitos can generate a population of thousands in just a couple of weeks. Let us have a closer look at these numbers. The mosquito life cycle includes four stages: egg, larva, pupa, and adult. For simplicity, we will make several assumptions that are not quite true in the nature: The egg stage lasts less than one day, and all the other stages are one week long. Each mosquito lives as a larva for the first week, the second week "hibernates" in the form of a pupa, and finally, the third week lives as an adult mosquito. At the end of its three-week life, each mosquito lays eggs and dies. To simplify things even further, we will assume that the transformation from one life stage into another always happens on Sunday. Each Sunday, the following things happen: \begin{itemize} \item An adult mosquito lays \textbf{E} eggs and dies. Within a day, one larva hatches from each egg. \item Some of the larvae hatched from egg the last Sunday were not strong enough and died or got eaten. Only every\textbf{R}-th larva will transform into a pupa on Sunday. \item An adult mosquito emerges from every \textbf{S}-th pupa, all other pupae dry. \end{itemize} For example, if there are \textbf{5} pupae and every \textbf{3}-rd of them survives, there will be \textbf{1} mosquito left. Out of \textbf{6} pupae, two adult mosquitos emerge. In the first week, there are \textbf{M} mosquitos, \textbf{P} pupae and \textbf{L} larvae. Calculate how many mosquitos will there be after \textbf{N}Sunday transformations. Of course, we are counting only living adult mosquitos, not the dry dead bodies. \InputFile The input consists of several instances, each instance per one line. Each line contains seven integers \textbf{M}, \textbf{P}, \textbf{L}, \textbf{E}, \textbf{R}, \textbf{S},\textbf{N} separated by space. \textbf{M}, \textbf{P} and \textbf{L} are the numbers of mosquitos, pupae, and larvae, respectively, in the first week. You may assume that \textbf{0} ≤ \textbf{M}, \textbf{P}, \textbf{L} ≤ \textbf{100000}, \textbf{0} ≤ \textbf{E} ≤ \textbf{100}, \textbf{1} ≤ \textbf{R}, \textbf{S} ≤ \textbf{10}, and \textbf{1} ≤ \textbf{N} ≤ \textbf{1000}. \textbf{E} is the number of eggs laid by one mosquito, \textbf{R} and \textbf{S} specify the survival rates of larvae and pupae, and \textbf{N} is the number of weeks. \OutputFile For each input instance, output a single line containing an integer number \textbf{C}, giving the count of mosquitos after the\textbf{N}-th Sunday. You may assume that the number of mosquitos during each of the first \textbf{N} weeks will not exceed \textbf{1000000}.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
10 20 40 4 2 2 10
144 55 8 0 1 9 4
10 10 10 2 3 2 6
10 20 40 86 9 9 999
Выходные данные #1
10
0
1
10