A permutation of $n$ is a one-to-one and onto function $p$ from $\{0,1,2,\dots,n-1\}$ to itself, such that $p(i) = p(j)$ if and only if $i=j$. The identity permutation is given by $p(i) = i$ for $0 \leq i < n$.
How to check whether $P$ can be written as some power of permutation $Q$ (i.e find $j$ such that $P=Q^j$, $P$ and $Q$ are permutation and given in problem)?
As the order of $Q$ is finite, let say equal to $m$ (i.e. $Q^m = Id$), compute $Q^i$ for $1 \le i \le m$ and verify at each step if $Q^i = P$. If yes, you win! If not, the problem has no solution.
Faster solution
Decompose $P,Q$ in cycles. Compute $Q^i$ and verify at each step if the cycle decomposition of $P,Q^i$ are the same.