help in insomnia 2017 question 2

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