Editorial for DMOPC '14 Contest 3 P4 - Not Enough Testers!


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.

Author: FatalEagle

Let N be the maximum of B over all the cases. We can precompute the number of factors for each number from 1 to N using a method like the Sieve of Eratosthenes. We iterate from 1 to N, and for each number we increase the number of factors of all its multiples by 1. The total time complexity is N times the partial sum for the harmonic series up to N, which can be proven to be \mathcal{O}(N \log N) in total. Then, for each possible value of K, we can put the number of numbers that have K as a factor into a list and then we can use binary search on the list associated with a query to answer all the queries. Since a number n has at most 2 \cdot \sqrt{n} factors, we can also use a prefix sum array here.

Time Complexity: \mathcal{O}((N + T) \cdot \log N) or \mathcal{O}(N \sqrt{N} + T)


Comments

There are no comments at the moment.