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.
William 2007-06-01