Editorial for COI '09 #2 Kolo
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
We use the sieve of Eratosthenes to find the first
Now we mark the square with
- If
, then is in the square so becomes . - Else, if
, then we can determine how many times the person in the square changes place with :- If
then becomes - Else
becomes
- If
Where
Let's assume that we know position
- If
, then was at before prime . - Else, if
: becomes- If
then becomes
The time complexity is
Comments