One of the key reductions in Shor's algorithm in quantum computing for finding prime factors of $m$ is that if $n < m$ is coprime with $m$, then there likely exists integers $p$ and $q$ where $mq+1=n^p$. Then since $$ mq = \underbrace{(n^{p/2}-1)}_{f_1}\underbrace{(n^{p/2}+1)}_{f_2} $$ then as long as $p$ is even and $q$ doesn't divide both$f_1$ or $f_2$, then at least one is a factor of $m$.
Can anyone give me a lead as to the reasoning behind the bolded statement? Is this a counting result? Is there a more precise statement? Is there a bound on how large $p$ may be?
Thanks!