Path: news.mathworks.com!not-for-mail
From: "naveen " <nkumarkuppili@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: reg matlab code for primitive roots
Date: Sat, 13 Nov 2010 18:43:03 +0000 (UTC)
Organization: Gitam University
Lines: 31
Message-ID: <ibmm7n$gvl$1@fred.mathworks.com>
Reply-To: "naveen " <nkumarkuppili@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1289673783 17397 172.30.248.35 (13 Nov 2010 18:43:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 13 Nov 2010 18:43:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2354798
Xref: news.mathworks.com comp.soft-sys.matlab:686545

function roots=primitive(num)
% num=7; for example
d=1;
k=0;
roots=0;

z=1;
for r=2 : (num-1)
    k=r^d;
    k=mod(k,num);
    
    while k>1
        
            d=d+1;
            k=k*r;
            k=mod(k,num);
            
    end
    if d==(num-1)
        roots(z,1)=r;
        z=z+1;
    end
    d=1;
end
z=z-1;
roots