Expplain the Logic Please

I couldn’t understand the logic of problem CodeChef: Practical coding for everyone. Please help me out.