Getting WA for The Rise and Fall of Power

,

Can someone tell whats wrong with my solution to this problem.
Problem-http://www.codechef.com/problems/A4/
My solution-http://www.codechef.com/viewsolution/2166013