The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
primitive root
09-01-2015, 01:28 PM
Post: #1
primitive root
function next_primitive_root(n,p) returns the smallest primitive root of "p" that is larger than "n"

example:

next_primitive_root(5, 13) returns 6
next_primitive_root(Ans,13) returns 7
<enter> returns 11
<enter> returns "no primitive roots exist"

Code:
#pragma mode( separator(.,;) integer(h32))

EXPORT next_primitive_root(n,p)
BEGIN
 local a,b,c,j,k;
 a:=euler(p);
 b:=ifactors(a);
 c:=length(b);
 for j from n+1 to p−1 do
  for k from 1 to c step 2 do
   if powmod(j,a/b(k),p) == 1 then
    break;
   end;
   if (k == c-1) and (gcd(j,p)==1) then
    return j;
   end;
  end;
 end;
 return "no primitive roots exist";
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
primitive root - roadrunner - 09-01-2015 01:28 PM



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