Editorial for DMOPC '16 Contest 2 P4 - Zeros
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Knowledge required: number theory, binary search
First of all, it is important to recognize the relationship between and its number of trailing zeros. A zero is formed with a pair of a factor of and a factor of . In fact, it is not necessary to account for the count of both, since the number of zeros is dependent on the lesser of the two, and the number of will always be less or equal than that of s.
To solve for the 50% subtask, we can simply brute-force the value of such that will have a number of trailing zeros in the range of .
Time Complexity:
To solve for the rest of the cases, it is important to recognize that the number of trailing zeros of will always be non-decreasing in relationship to an increasing . Hence, we can use binary search to find:
- The minimum such that has at least trailing zeros.
- The maximum such that does not have more than trailing zeros.
The number of valid values of can be calculated by subtracting the two and adding one.
Time Complexity:
Comments