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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Note that the function increases by one every multiple of 2 it hits, and decreases by 1 every multiple of 7 it hits. Since there are 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 , and then just check the 6 numbers after it.
Time Complexity:
Comments