I read the boards every single day, @Chronos. I was pleasantly surprised to see this old topic come up. I’m no longer a mathematician in my day job, but I’ll jump at any excuse to talk algebraic number theory.
@csstudent, I am assuming that you are approaching this topic from a coding point of view: you want to write code to find full reptend primes, and you are not so much interested in the theory behind it. If I’m mistaken, please correct me. There is quite a bit of theory (I mentioned it briefly above), and modern analytic and algebraic tools in algebraic number theory and class field theory have yielded beautiful results relating primes which have a particular primitive root to the splitting/ramification behavior of prime ideals in algebraic number fields.
But unless you really want to know that theory, we’ll stick to an algorithm (hopefully as efficient as possible, much more on that later) to determine whether a given prime p is a full reptend prime. As I mentioned seven years ago, prime p is a full reptend prime if and only if 10 is a primitive root modulo p.
If I understand your code correctly, you are finding all of the primitive roots modulo a given prime p (again, please correct me if I am wrong). There is no need to do that. There are exactly phi(p-1) incongruent primitive roots modulo p, where phi is the Euler totient function. Instead of doing that, just determine whether the multiplicative order of 10 modulo p is equal to p-1. It is that simple. I have never checked, but I’m sure someone has written a function in some library to calculate the multiplicative order of an integer modulo some modulus. As a CS student, you should be able to whip it up in just a few lines of code.
But here is the huge, huge caveat: except for the deep deep theory I mentioned above, determining the multiplicative order of 10 modulo p requires us to know the prime factorization of p-1 if we have any hope of doing the calculation for large p in tractable time. As a CS student, I expect you know, or will know soon, that there is no known algorithm for determining the prime factorization of large integers in polynomial time. If you find such an algorithm, please mention me in your speech when accepting the Millennium Prize.
The number of prime divisors of p-1 has normal order log log p-1, and so grows without bound as p does. From elementary group theory, we know that the multiplicative order of 10 in the finite field with p elements is a divisor of p-1. If we know the prime factorization of p-1, just calculate 10^k modulo p for each divisor k of p-1 less than p-1. If any of those powers is congruent to 1 modulo p, then p is not a full reptend prime. If none of those powers is congruent to 1 modulo p, then p is a full reptend prime. Q.E.D.
I will be interested to see your code. I expect even if you use a library function, it will not run in polynomial time.
Thank you for the question. I’m a data analyst these days, I don’t teach (or really study) math any more. But I still love it.