What's wrong in my approach

i have taken a dp array which will store pow(a,i)%p where i is the index of array.Then final i will take the product of every dp array element by simultaneously taking mod with p.
link to my solution

i have taken pow(a,i+1)%p instead of pow(a,i)%p if i is the index of dp array.(it was a typing mistake in asking doubt above)

understood the mistake i am doing .the finalans which i am calculating is wrong.