Help me with this problem

https://www.codechef.com/LTIME86B/problems/PRT2