1

I have a problem to solve that is the following,

I have a big prime number and i need to test if for example 2 is a primitive root a this big prime number, is there any easy way of doing this?

Thanks in advance.

Micah
  • 38,108
  • 15
  • 85
  • 133
Philipe
  • 11

1 Answers1

2

We answer the question about $2$ and $19$ raised in a comment, and generalize somewhat.

We want to know whether $2$ has order $18$ modulo $19$. If it doesn't, then $2^6\equiv 1\pmod{19}$ or $2^9\equiv 1\pmod{19}$. For the order of $2$ divides $18$, and if it is not $18$, it must divide $6$ or $9$.

Note that $2^6=64\equiv 7\pmod{19}$. So $2^9\equiv 8\cdot 7=56\equiv -1\pmod{19}$, and we are finished: $2$ is a primitive root.

In general, suppose that $p-1$ has the prime power factorization $p_1^{a_1}\cdots p_k^{a_k}$. Then if $a$ has order $\lt p-1$ modulo $p$, we must have that $a^{m_i}\equiv 1\pmod{p}$ for some $m_i$, where $m_i=\frac{p-1}{p_i}$.

If we can determine the primes that divides $p-1$ cheaply (a very big if!) then modular exponentiation can be used to settle the question of whether $a$ is a primitive root of $p$. Modular exponentiation is fast, even for large $p$, if we use the binary method.

Added: Suppose that $d\lt p-1$ is the order of $a$ modulo $p$, where $p-1=p_1^{a_1}\cdots p_k^{a_k}$. Then $d=p_1^{b_1}\cdots p_k^{b_k}$ where some of the $b_i$ may be $0$, and $b_i\le a_i$ for all $i$, and $b_i\lt a_i$ for at least one $i$.

In that case, $d$ divides $\frac{p-1}{p_i}$, and therefore if $a^d\equiv 1\pmod{p}$, we must also have $a^{(p-1)/p_i}\equiv 1\pmod{p}$. Thus to test whether some power of $a$ les than $p-1$ is congruent to $1$, we need only test the powers $\frac{p-1}{p_i}$.

André Nicolas
  • 507,029
  • can u explain better the part of the choose of 6 and 9? i didnt understand. Is there a way that we dont need to test all exponent since p-1 until 1 ? thanks in advance – Philipe Nov 12 '13 at 06:21
  • I have added the calculation, for the general situation. But to apply to our particular numbers, the order of $2$ must divide $18$. If it was, say, $2$, then we would have $a^2\equiv 1$ and therefore $a^6\equiv 1$. So if we show that $2^6\not\equiv 1$, it follows automatically that $2^2\not\equiv 1$. – André Nicolas Nov 12 '13 at 06:34
  • So that means that means that i only have to test powers of 2? – Philipe Nov 12 '13 at 10:20
  • More. Let the prime be $p=191$. To find out whether $a$ is a primitive root of $191$, it would be enough to check whether one of $a^{95}$, $a*{38}$, or $a^{10}$ is congruent to $1$ mod $191$. If none is, then $a$ is a primitive root of $191$. – André Nicolas Nov 12 '13 at 11:43
  • Ok, i understood the a^95, but how/why do you used 38 and 10? Thanks – Philipe Nov 12 '13 at 12:33
  • I divided #190$ by the other two primes that divide it, $5$ and $19$. – André Nicolas Nov 12 '13 at 14:50
  • The thing is im developing a program to determine if a number is a primitive root of a prime... The rule that i understood is test a^(p/2)mod p different from 1. The thing you did with 38 and 10 change with the prime number right? – Philipe Nov 12 '13 at 20:36
  • Yes, it changes. There is a big literature on efficient tests for primitive root. I imagine that in your previous comment you meant $a^{(p-1)/2}$. If that's congruent to $1$, then for sure $a$ is not a primitive root. If it is congruent to $-1$, then for sure $a$ is a primitive root. If it is something else (and it definitely can be) then $a$ may or may not be a primitive root. – André Nicolas Nov 12 '13 at 20:51
  • yes it was that, so i can be sure that the number is a primitive root if the a^((p-1)/2)mod p different from one, and a^(p-1)mod p=1 right? – Philipe Nov 12 '13 at 23:26
  • I am sorry, but how many times do I have to tell you that the answer is no? If you know it for all $\frac{p-1}{p_i}$ where $p_i$ ranges over all of the prime divisors of $p-1$, then the answer is yes. – André Nicolas Nov 13 '13 at 00:27
  • yes you are right (sorry to bother) is just that im seing that its impossible to test all numbers if the prime is to big... if we test if the number 3 is a primitive root we do the same test as we if it was 2? this is 3^((p-1)/2)mod p or we do 3^((p-1)/3)mod p ? – Philipe Nov 13 '13 at 01:09
  • It is $3^{(p-1)/p_i}$. It is good to start with $p_i=2$, and go to other prime divisors of $p-1$ if $p_i=2$ does not settle things. The powers we use have nothing to do with $a$. – André Nicolas Nov 13 '13 at 01:12
  • Thanks mate :D i think i have understood everything for now, really thanks :D – Philipe Nov 13 '13 at 20:56
  • You are welcome. For more advanced ways of doing it, see a text on computational number theory. – André Nicolas Nov 13 '13 at 21:23