Question: Prime inverses in Zp

Hi, 

I am interested to find the primes in in field Zp which Have prime inverses.  In particular, for any prime p up to an arbitrary number N, the number of pairs (a,b) where a and b are mutually inverse primes <p in Zp. Obviously in this context (a,b) is the same as (b,a) so no need for double counting. What I have so far is the following simple code for finding the inverse of prime q<p, given a chosen value of p. I can then see which results are prime and which are composite.

N:=p:

for n from 1 to N do

X:=q*n-1;

if mod(X,p)=0 then print(n);

end if:

end do:

This “hand cranking” method works but is of course boring but I don’t know how to scale it up to a more efficient code as described above. I would be grateful to anyone  able to assist me with this.

Thanks in advance

David

Please Wait...