so , Given an equation *(N*(A^N))%P=B

where value of N can vary from [1,X] and

value of X can be as high as 10^12.

All other numbers A,B,P and X as well are given and we have to find the number of Ns that satisfy the equation.

Any Idea on how to solve this?