help in insomnia 2017 question 2

recently i tried a problem from insomnia 2017 . problem link is INSQ17E Problem - CodeChef my solution was giving wrong ans but all the test cases are working fine on my machine ,
this is my code CodeChef: Practical coding for everyone
everybody is using fast exponentiation to get the answer i am not getting why they are using it, help me out.