Editorial for PIB '20 P2 - 2 + 2 = 5


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: ChrisT

Note that the function f(x) = \left\lfloor \frac{x}{2} \right\rfloor - \left\lfloor \frac{x}{7} \right\rfloor increases by one every multiple of 2 it hits, and decreases by 1 every multiple of 7 it hits. Since there are \ge 3 multiples of 2 in between any two multiples of 7, the function is strictly increasing upon multiples of 7. We also note that for this same reason, the multiples of 7 are the local minima of this function. With this knowledge, we can binary search for the last multiple of 7 such that f(x) \le T, and then just check the 6 numbers after it.

Time Complexity: \mathcal{O}(\log T)


Comments

There are no comments at the moment.