IMPRS - Check my code

Is logic implementation wrong?

Please check it - CodeChef: Practical coding for everyone)