Post Reply 
Looking for a Primitive Roots program
09-02-2015, 10:43 PM
Post: #9
RE: Looking for a Primitive Roots program
Well, as I yesterday had started to write that program as a CAS-program, I finished it today and want to give it as another example which is much shorter and needs one loop less, as it uses more of the built-in list capabilities, so it should be much faster, but I haven't checked that
Code:

#cas
PrimW(n):=
BEGIN
local l,i,phin,l1;
phin:=euler(n);
l:=ifactors(phin);
l1:=phin/revlist(MAKELIST(l(i),i,1,size(l),2));
l:={};
FOR i FROM 2 TO n-1 DO
IF pos(powmod(i,l1,n),1)==0 THEN
l:=append(l,i);
END;
END;
 return l;
END;
#end
Perhaps it is even possible to omit the second loop, as powmod({2,3,...n-1},{...},n) works, but that provides a list of lists, and here the first objects of all lists belong to 2, the second objects to 3 etc, which makes checking the results difficult.
Arno
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Looking for a Primitive Roots program - Arno K - 09-02-2015 10:43 PM



User(s) browsing this thread: 1 Guest(s)