I have been recently reading the paper "PRIMES is in P", but unfortunately a lot of the steps were skipped, which led to confusion. My main problem is with the upper bound on r which was not explained at all in the paper(i don't see the connection of these bounds to the runtime of the algorithm), for example how did they come up with the upper bound O(log^5 n) for r, why is it exactly this number? why not O(log^2 n) or something else. Moreover they had set a condition for r in the second step of the algorithm. They wanted the order of r mod n to be greater than log^2 n, but i don't see why this has anything to do with polynomial runtime or why does it have to be greater than log^2 n.
Can anyone please explain why this is true? or how to derive these numbers?