Editorial for TLE '17 Contest 5 P3 - Willson and Factorization
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For the first of the points, we note that when is prime, then all from to satisfy , so by Bézout's Lemma, there exist such that , or equivalently, . That is, every non-zero element in is a unit.
We can either simply print all numbers from to as a unit, but code that has a correct unit check, does not check if a unit is irreducible or prime, and does not time out will also pass.
Time Complexity: or (unit checking only)
For the next of the points, we brute force check if elements are units or not in time by checking every possible pair of elements. Then, we brute force check if elements are irreducible or not in by checking every possible triple of non-units.
To find prime elements, we try every possible combination of to check if is prime.
Time Complexity:
For the next , we note that we do not need to try every possible combination of and instead, we just need to go over every possible , using booleans to mark when .
Time Complexity:
For full points, we precompute whether or not for any pair , there exists such that . This can be done in time. In fact, we say that divides when this is true.
Then, we only need to go over every possible , using the precomputed divisibility array.
Time Complexity:
Comments