help in insomnia 2017 question 2

recently i tried a problem from insomnia 2017 . problem link is https://www.codechef.com/problems/INSQ17E my solution was giving wrong ans but all the test cases are working fine on my machine ,
this is my code https://www.codechef.com/viewsolution/15439325
everybody is using fast exponentiation to get the answer i am not getting why they are using it, help me out.

//