Proof.
Let

.
The order of

is a divisor

of
the order

of the group

.
Write

, for some divisor

of

.
If

is not a generator of

, then
since

, there is a prime divisor

of

such that

.
Then
Conversely, if

is a generator, then

for any

. Thus the algorithm terminates with step
3
if and only if the

under consideration is a primitive root.
By Theorem
2.5.8 there is at least one primitive
root, so the algorithm terminates.