Editorial for LCC '24 Contest 2 J4 - Eric's Apple Harvest
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
IM SORRY FOR MAKING THIS PROBLEM SO HARD :sob: :sob: :sob:
This problem can be simplified into the following math problem:
Find all such that .
Subtask 1
It suffices to loop through all values from to , inclusive, and to check if each one satisfies the modular equation.
Time Complexity:
Space Complexity:
Subtask 2
Since is prime, there is exactly one solution to this modular equation.
The key to this subtask is to notice if , then , for . The proof of this statement is left to the reader.
By doing so, it suffices to loop from to to find the solution of the equation. Then, since any solution is of the form , it is now a case of counting how many values of are valid given than .
Time Complexity:
Space Complexity:
Additional Info
It is possible to solve this problem using modular inverse.
I cannot promise the next J4 will not be this bad...
Comments