Sz\303\241m\303\255t\303\263g\303\251pes sz\303\241melm\303\251letJ\303\241rai AntalEzek a programok csak szeml\303\251ltet\303\251sre szolg\303\241lnak1. A pr\303\255mek eloszl\303\241sa, szit\303\241l\303\241s2. Egyszer\305\261 faktoriz\303\241l\303\241si m\303\263dszerek3. Egyszer\305\261 pr\303\255mtesztel\303\251si m\303\263dszerekrestart; with(numtheory);3.1. K\303\251rd\303\251s.3.2. Feladat.#
# This procedure do Wilson's test. The return value
# is a pair of lower two digits of (n-1)!+1 in base n.
#
wilsontest:=proc(n::posint) local i,r,m;
r:=1; m:=n^2;
for i from 2 to n-1 do r:=r*i mod m od;
r:=r+1 mod m; [irem(r,n),iquo(r,n)] end;#
# This procedure do Wilson's test and
# look for Wilson numbers until a given
# limit.
#
wilson:=proc(n) local i,r,p,w;
p:=[]; w:=[];
for i from 2 to n do
r:=wilsontest(i);
if r[1]=0 then
p:=[op(p),i];
if r[2]=0 then w:=[op(w),i] fi
fi
od; [w,p] end;wilson(1000);3.3. Probl\303\251ma.3.4. Fermat-teszt.n:=(2^28-9)/7; 3&^(n-1) mod n; 2&^(n-1)mod n;3.5. Feladat.3.6. Feladat.3.7. Feladat.3.8. Lemma.3.9. Lemma.3.10. T\303\251tel.3.11. Defin\303\255ci\303\263.3.12. Euler t\303\251tele.3.13. Gauss lemm\303\241ja.3.14. Gauss kvadratikus reciprocit\303\241si t\303\266rv\303\251nye.3.15. Defin\303\255ci\303\263.3.16. T\303\251tel.3.17. P\303\251lda.3.18. A Jacobi-szimb\303\263lum kisz\303\241m\303\255t\303\241sa.#
# This recursive procedure calculates
# the Jacobi symbol (n|m) for integers
# m>2 and n, where m is odd.
#
jacobisymbol:=proc(n::integer,m::posint) local s;
if type(m,even) then error "second argument must be odd" fi;
if n=0 then RETURN(0) fi;
if n=1 then RETURN(1) fi;
if n<0 then
if type((m-1)/2,odd) then
RETURN(-jacobisymbol(-n,m))
else
RETURN(jacobisymbol(-n,m))
fi
fi;
if type(n,even) then
if type((irem(m,16)^2-1)/8,odd) then
RETURN(-jacobisymbol(n/2,m))
else
RETURN(jacobisymbol(n/2,m))
fi
fi;
if n>m then RETURN(jacobisymbol(irem(n,m),m)) fi;
if type(irem((m-1)/2,2)*irem((n-1)/2,2),odd) then
-jacobisymbol(m,n)
else
jacobisymbol(m,n)
fi
end;debug(jacobisymbol); jacobisymbol(76,131);3.19. Feladat.3.20. Feladat.interface(verboseproc=2);print(jacobi);3.21. Feladat.print(legendre);3.22. Soloway-Strassen-teszt.n:=561; 5&^(n-1) mod n; 5&^((n-1)/2) mod n; jacobi(5,n);3.23. Feladat.3.24. Miller-Rabin-teszt.millerrabin:=proc(n::posint,b::posint) local j,e,r,bb;
if n<9 then ERROR(`first parameter is too small`,n) fi;
if type(n,even) then ERROR(`first parameter is even`,n) fi;
if b<2 then ERROR(`second parameter is too small`,b) fi;
if n<=b then ERROR(`second parameter is too large`,b) fi;
e:=0; r:=n-1;
while type(r,even) do e:=e+1; r:=r/2 od;
bb:=modp(b&^r,n); if bb=1 then RETURN(FAIL) fi;
for j to e while bb<>n-1 do bb:=modp(bb&^2,n) od;
if j=e+1 then RETURN(false) fi; FAIL; end;rabin:=proc(n::posint,m::posint) local i,j,b,e,r,rnd;
if n<9 then ERROR(`first parameter is too small`,n) fi;
if type(n,even) then ERROR(`first parameter is even`,n) fi;
rnd:=rand(2..n-1); e:=0; r:=n-1;
while type(r,even) do e:=e+1; r:=r/2 od;
for i to m do
b:=rnd();
if 1<gcd(b,n) then RETURN(false) fi;
modp(b&^r,n); if %=1 then next fi;
for j to e while %<>n-1 do modp(%&^2,n) od;
if j=e+1 then RETURN(false) fi;
od; FAIL end;trueisprime:=proc(n::posint) local f;
if n<2 then RETURN(false) fi;
if n=2 or n=3 or n=5 or n=7 or n=11 or n=13 then RETURN(true) fi;
if 1<gcd(n,30030) then RETURN(false) fi;
if n<289 then RETURN(true) fi;
if 1<gcd(n,247110827) then RETURN(false) fi;
f:=millerrabin(n,2); if f=false then RETURN(f) fi;
f:=millerrabin(n,3); if f=false then RETURN(f) fi;
if n<1373653 then RETURN(true) fi;
f:=millerrabin(n,5); if f=false then RETURN(f) fi;
if n< 5326001 then RETURN(true) fi;
f:=millerrabin(n,7); if f=false then RETURN(f) fi;
if n<3215031751 then RETURN(true) fi;
f:=millerrabin(n,11); if f=false then RETURN(f) fi;
if n<2152302898747 then RETURN(true) fi;
f:=millerrabin(n,13); if f=false then RETURN(f) fi;
if n<3474749660383 then RETURN(true) fi;
f:=millerrabin(n,17); if f=false then RETURN(f) fi;
if n<341550071728321 then RETURN(true) fi; FAIL end;3.25. Feladat.3.26. Feladat.3.27. Miller t\303\251tele.3.28. Feladat.3.29. Lucas-teszt.#
# This procedure do Lucas' test
# for the number n on the naive way
# using base a
#
naivelucastest:=proc(n,a) local m;
if igcd(a,n)>1 then RETURN(false) fi;
if modp(a&^(n-1),n)<>1 then RETURN(false) fi;
for m from 2 to n-2 do
if modp(a&^m,n)=1 then RETURN(false) fi
od; true end;3.30. Feladat.3.31. P\303\251pin-teszt.3.32. Feladat.3.33. Pocklington-Lehmer-teszt.3.34. Feladat.3.35. Feladat.3.36. Proth-teszt.3.37. Feladat.proth:=proc(h::posint,m::posint) local a,b,n,ad; n:=h*2^m+1;
if h>=2^m or not type(h,odd) then return FAIL fi;
if m=1 or m=2 then return true fi;
# 2 is not a quadratic residue mod n, we start with 3
a:=3; b:=2&^m mod a; b:=h*b+1 mod a;
# by quadratic reciprocity, (a|n)=(n|a)=(b|a)
if jacobi(b,a)=0 then return false fi;
if jacobi(b,a)=-1 then
if a&^((n-1)/2) mod n=n-1 then return true else return false fi;
fi;
# we shall use the quasi-prime sequence 5,7,11,13,17,19,23,25,..
# a random base would give only two trials in mean,
# and this looks even better
a:=5; ad:=2;
while true do
b:=2&^m mod a; b:=h*b+1 mod a;
if jacobi(b,a)=0 then return false fi;
if jacobi(b,a)=-1 then
if a&^((n-1)/2) mod n=n-1 then return true else return false fi;
fi;
a:=a+ad; ad:=6-ad;
od;
end;
proth(11,5);ifactor(11*2^5+1);3.38. T\303\251tel.3.39. Feladat.4. Lucas-sorozatok5. Alkalmaz\303\241sok 6. Sz\303\241mok \303\251s polinomok7. Gyors Fourier-transzform\303\241ci\303\2638. Elliptikus f\303\274ggv\303\251nyek9. Sz\303\241mol\303\241s elliptikus g\303\266rb\303\251ken10. Faktoriz\303\241l\303\241s elliptikus g\303\266rb\303\251kkel11. Pr\303\255mteszt elliptikus g\303\266rb\303\251kkel12. Polinomfaktoriz\303\241l\303\241s13. A szita m\303\263dszerek alapjai14. Az AKS tesztLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn