CCCGuide

Problem J2: Epidemiology

2020 · J2 · Original problem · DMOJ

Problem Description

People who study epidemiology use models to analyze the spread of disease. In this problem, we use a simple model.

When a person has a disease, they infect exactly RR other people but only on the very next day. No person is infected more than once. We want to determine when a total of more than PP people have had the disease.

(This problem was designed before the current coronavirus outbreak, and we acknowledge the distress currently being experienced by many people worldwide because of this and other diseases. We hope that including this problem at this time highlights the important roles that computer science and mathematics play in solving real-world problems.)

Input Specification

There are three lines of input. Each line contains one positive integer. The first line contains the value of PP. The second line contains NN, the number of people who have the disease on Day 00. The third line contains the value of RR. Assume that P≤107P \leq 10^7 and N≤PN \leq P and R≤10R \leq 10.

Output Specification

Output the number of the first day on which the total number of people who have had the disease is greater than PP.

Sample Input 1

750
1
5

Output for Sample Input 1

4

Explanation of Output for Sample Input 1

The 11 person on Day 00 with the disease infects 55 people on Day 11. On Day 22, exactly 2525 people are infected. On Day 33, exactly 125125 people are infected. A total of 1+5+25+125+625=7811+5+25+125+625=781 people have had the disease by the end of Day 44 and 781>750781 > 750.

Sample Input 2

10
2
1

Output for Sample Input 2

5

Explanation of Output for Sample Input 2

There are 22 people on Day 0 with the disease. On each other day, exactly 22 people are infected. By the end of Day 44, a total of exactly 1010 people have had the disease and by the end of Day 55, more than 1010 people have had the disease.