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\263dszerekLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn4. Lucas-sorozatok5. Alkalmaz\303\241sok 6. Sz\303\241mok \303\251s polinomokrestart;6.1. \303\226sszehasonl\303\255t\303\241s, \303\266sszead\303\241s, kivon\303\241s.#
# We fix a base. For demo purposes:
#
B:=10;`mod`:=modp;#
# Carry addition to long number s
#
cadd:=proc(s,c) local i,r,cc,x; global B;
r:=[]; cc:=c;
for i from 1 to nops(s) do
x:=s[i]+cc mod B;
cc:=(s[i]+cc-x)/B;
r:=[op(r),x]
od; [r,cc] end;#
# Carry subtraction from long number s
#
csub:=proc(s,c) local i,r,cc,x; global B;
r:=[]; cc:=c;
for i from 1 to nops(s) do
x:=s[i]-cc mod B;
cc:=-(s[i]-cc-x)/B;
r:=[op(r),x]
od; [r,cc] end;ss:=convert(100,base,B); csub(ss,2);#
# Comparision of long numbers
#
cmp:=proc(s1,s2) local i;
if nops(s1)>nops(s2) then RETURN(1) fi;
if nops(s1)<nops(s2) then RETURN(-1) fi;
for i from nops(s1) by -1 to 1 do
if s1[i]>s2[i] then RETURN(1) fi;
if s1[i]<s2[i] then RETURN(-1) fi;
od; 0 end;s1:=convert(123,base,B); s2:=convert(321,base,B); cmp(s1,s2);#
# Addition with carry, n digit
#
addc:=proc(s1,s2,c,n) local i,r,cc,x; global B;
r:=[]; cc:=c;
for i from 1 to n do
x:=s1[i]+s2[i]+cc mod B;
cc:=(s1[i]+s2[i]+cc-x)/B;
r:=[op(r),x]
od; [r,cc]; end;addc(s,s1,2,3);#
# Subtraction with carry, n digit
#
subc:=proc(s1,s2,c,n) local i,r,cc,x;
r:=[]; cc:=c;
for i from 1 to n do
x:=s1[i]-s2[i]-cc mod B;
cc:=-(s1[i]-s2[i]-cc-x)/B;
r:=[op(r),x]
od; [r,cc] end;subc(s1,s2,2,3);6.2. Szorz\303\241s \303\251s polinomszorz\303\241s.x:='x'; i:='i';
s1:=convert(123,base,B); p1:=add(s1[i]*x^(i-1),i=1..nops(s1));
s2:=convert(321,base,B); p2:=add(s2[i]*x^(i-1),i=1..nops(s2));
convert(123*321,base,B); expand(p1*p2);
convert(1002003*3002001,base,B^3);6.3. Klasszikus algoritmusok a szorz\303\241sra \303\251s az oszt\303\241sra.6.4. Karacuba szorz\303\241s.#
# Single digit multiplication
#
mul11:=proc(x,y) global B;
convert(x[1]*y[1],base,B);
[%[1],%[2]] end;mul11([2],[7]);#
# Karatsuba's method; x and y are lists of nonnegative
# digits with lenght 2^n.
#
kara:=proc(x,y,n)
local m0,m00,m01,m1,m10,m11,m2,m20,m21,f,x0,x1,y0,y1,z0,z1,c0,c1;
if n=0 then RETURN(mul11(x,y)) fi;
x0:=[x[1..2^(n-1)]];
x1:=[x[1+2^(n-1)..2^n]];
y0:=[y[1..2^(n-1)]];
y1:=[y[1+2^(n-1)..2^n]];
m0:=kara(x0,y0,n-1);
m00:=[m0[1..2^(n-1)]];
m01:=[m0[1+2^(n-1)..2^n]];
m2:=kara(x1,y1,n-1);
m20:=[m2[1..2^(n-1)]];
m21:=[m2[1+2^(n-1)..2^n]];
f:=true;
if cmp(x1,x0,2^(n-1))>=0 then
z0:=subc(x1,x0,0,2^(n-1))[1]
else
z0:=subc(x0,x1,0,2^(n-1))[1];
f:=not f;
fi;
if cmp(y1,y0,2^(n-1))>=0 then
z1:=subc(y1,y0,0,2^(n-1))[1];
else
z1:=subc(y0,y1,0,2^(n-1))[1];
f:=not f;
fi;
m1:=kara(z0,z1,n-1);
m10:=[m1[1..2^(n-1)]];
m11:=[m1[1+2^(n-1)..2^n]];
z0:=addc(m01,m20,0,2^(n-1));
c0:=z0[2];
z1:=addc(z0[1],m00,0,2^(n-1));
c1:=c0+z1[2];
z0:=addc(z0[1],m21,c1,2^(n-1));
c0:=c0+z2[2];
m21:=cadd(z0[1],m21,c0,2^(n-1));
if f then
z1:=subc(z1[1],m10,0,2^(n-1));
c1:=z1[2];
z0:=subc(z0[1],m11,c1,2^(n-1));
c0:=z0[2];
m21:=csub(m21[2],c2);
else
z1:=addc(z1[1],m10,0,2^(n-1));
c1:=z1[2];
z0:=addc(z0[1],m11,c1,2^(n-1));
c0:=z2[2];
cadd(m21[1],c0);
fi; [op(m00),op(z1[1]),op(z0[1]),op(m21[1])] end;7. 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. Az AKS teszt14. A szita m\303\263dszerek alapjaiLUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn