##### Canadian Computing Competition: 2020 Stage 1, Junior #2

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 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 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 . The second line contains , the number of people who have the disease on Day . The third line contains the value of . Assume that and and .

#### Output Specification

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

#### Sample Input 1

```
750
1
5
```

#### Output for Sample Input 1

`4`

#### Explanation of Output for Sample Input 1

The person on Day with the disease infects people on Day . On Day , exactly people are infected. On Day , exactly people are infected. A total of people have had the disease by the end of Day are .

#### Sample Input 2

```
10
2
1
```

#### Output for Sample Input 2

`5`

#### Explanation of Output for Sample Input 2

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

## Comments

Two questions:

When P = 500000 and and N = 1 and R = 2, what should the output be?

In Sample Input 2, shouldn't the output be

`3`

?On Day 0, 2 people are infected.

On Day 1, another 2 people are infected. The total amount of people infected now is 4.

On Day 2, another four people are infected, as there are 4 infected people and they each infect R (1) person. The amount of people now infected is 8.

Then on Day 3, another 8 people are infected, as there are 8 infected people and they each infect R (1) person. The amount of people infected now is 16.

Now it is more than 10, so by my calculation it should be

`3`

. I'm probably missing something, could anyone tell me? Thank you very much.I think my code kind of stuffs up when R = 1.

A person can only infect another person

onceand only on the next day.On day , people are infected.

On day , more people are infected ( previously infected + currently infected = ).

On day , more people are infected ( previously infected + currently infected = ).

On day , more people are infected ( previously infected + currently infected = ).

On day , more people are infected ( previously infected + currently infected = ).

On day , more people are infected ( previously infected + currently infected = ).

If you need further help with this question, please join the DMOJ Slack or DMOJ Discord.

This contradicts your explanation of Day 2.

Thank you for help maxcruickshanks and d.

For those who are stuck on this problem:

I thought originally that ‘they infect exactly R other people but only on the very next day’ meant that they only start infecting others on the very next day and

they keep infecting others every day after that. maxcruickshanks’s comment and d’s comment told me that what it really means is that they only infect a person on the next day andstop infecting others once they have infected R people. Bad comprehension by me, so thanks for pointing that out.Test your code that it works for test cases when R = 1. Very interesting and challenging problem, 👍 to the creator. I would probably cry if I was taking part in CCC 2020 😂.

If you try to solve this using the pow() function in python, you will likely get TLE errors. Instead, try to find another way to keep track of current infections and new infections without have to calculate from day 0 to current day for every iteration of the loop.

Hope this helps someone else.

This comment is hidden due to too much negative feedback. Click here to view it.

If R is 1 then the code kinda gets messed up i think.

Switching to PyPy 3 fixed that problem for me, so it might be worth a try in your case

Firstly, the number of lines is a poor indication of runtime. Consider the following program:

it's only 2 lines, but will clearly take longer than the 4-line long program:

Your issue is that Python is quite slow, and might time out if you need to loop for many days. Can you find a way to compute the answer for small values of and without looping?

It's a very interesting challenge though.

This question was surprisingly difficult compared to the other questions during this years contest

Not really.

This comment is hidden due to too much negative feedback. Click here to view it.

Well, it can be seen as a geometric sequence, where the first term is N, common ratio is R, and the sum of geometric sequence is P. So the second case is the situation which the common ratio is 1, then the total number of people who are infected is N times day = 2 times (5 + 1) = 12. My code has passed and I used the formulas of geometric sequence

When someone is infected, they infect R other people ONLY on the very next day, not every day after they are infected.

Kinda doesn't make any sense when you think about it intuitively, but I guess it's what it is.

Like people don't stop infecting others when they've already infected someone, how would they know?