Chef and Modulo Game Problem

i dont think this platform is made for sharing approaches for ongoing competition problems.
we could help you improve your approach if u are anywhere near.
math's concept called combinatorics
If you got TLE then you probably just coded a brute force solution.
These problems are designed so that you actually have to think to solve them.
Make sample inputs.
Try simplified versions.
Make a table.
Look for the pattern.
you are getting TLE because you must be running 3 nested loops O(n^3).

This question can be actually solved in O(logn). Just think about how to maximize the value of the mod operator keeping in mind that directly maximizing it would give 0 as the final answer...I would leave it up to you to figure out why this is the case. Once you have that figured out, you just have to apply some combinatorics.
PS there is one major edge case which costed me 2 WA's before I got an AC.
come after the contest is over.
till then hints provided are enough for you to apply your brain.
@Repo, If you don't understand then you should lose. Hence the word "contest".
Topic archived. No new replies allowed.