Primitive root modulo n

In modular arithmetic, a number g is a primitive root modulo n, if every number m from 1..(n-1) can be expressed in the form of gx≡m(modn). As an example, 3 is a primitive root modulo 7:

31≡3 (mod7)
32≡2 (mod7)
33≡6 (mod7)
34≡4 (mod7)
35≡5 (mod7)
36≡1 (mod7)

All the elements 1,2,…,6 of the group modulo 7 can be expressed that way. The number 2 is no primitive root modulo 7, because

23=8≡1(mod7)

and

26=64≡1(mod7)