Bevezet\303\251s a matematik\303\241ba
J\303\241rai Antal
Ezek a programok csak szeml\303\251ltet\303\251sre szolg\303\241lnak.
2. Term\303\251szetes sz\303\241mok
6. Sz\303\241melm\303\251let
6.1. Oszthat\303\263s\303\241g
6.1.15. Felbonthatatlan elem \303\251s pr\303\255melem.
6.1.18. Legnagyobb k\303\266z\303\266s oszt\303\263, legkisebb k\303\266z\303\266s t\303\266bbsz\303\266r\303\266s, relativ primek.
6.1.24. Legnagyobb k\303\266z\303\266s oszt\303\263, legkisebb k\303\266z\303\266s t\303\266bbsz\303\266r\303\266s az eg\303\251sz sz\303\241mok k\303\266r\303\251ben.
6.1.25. B\305\221v\303\255tett euklid\303\251szi algoritmus.
exgcd:=proc(a::integer,b::integer) local n,x,y,r,q;
x[0]:=1;y[0]:=0;r[0]:=a;x[1]:=0;y[1]:=1;r[1]:=b;n:=0;
do if r[n+1]=0 then return x[n],y[n],r[n] fi;
q[n+1]:=floor(r[n]/r[n+1]);r[n+2]:=r[n]-q[n+1]*r[n+1];
x[n+2]:=x[n]-q[n+1]*x[n+1];y[n+2]:=y[n]-q[n+1]*y[n+1];
n:=n+1;
od; end;
exgcd(12,18); exgcd(-12,-18); igcdex(12,18,'x','y'); x; y;
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
6.1.26. Megjegyz\303\251s.
exgcd:=proc(a::integer,b::integer) local x0,x1,x2,y0,y1,y2,r0,r1,r2,q;
x0:=1;y0:=0;r0:=a;x1:=0;y1:=1;r1:=b;
do if r1=0 then return x0,y0,r0 fi;
q:=floor(r0/r1);r2:=r0-q*r1;
x2:=x0-q*x1;y2:=y0-q*y1;
r0:=r1;r1:=r2;x0:=x1;x1:=x2;y0:=y1;y1:=y2;
od; end;
exgcd(12,18);
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
6.1.42. Feladat: Lam\303\251 t\303\251tele.
6.1.45. Feladat: bin\303\241ris lnko.
6.1.76. Tov\303\241bbi feladatok megold\303\241sokkal.
6.1.77. Tov\303\241bbi feladatok.
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
6.2. Kongruenci\303\241k
restart;
6.2.3. Marad\303\251koszt\303\241lyok.
13 mod 7; modp(13,7); `mod`(13,7); mods(13,7); `mod`:=mods; 13 mod 7;
`mod`:=modp; [2,10] mod 8; [2,8] mod 8; [8,1,10,19,4,29,-10,7] mod 8;
mods(%,8); [1,19,29,7] mod 8;
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
6.2.8. Diszkr\303\251t logaritmus probl\303\251ma.
*6.2.9. Gyors hatv\303\241nyoz\303\241s.
fastexp:=proc(g,n::posint,mult::procedure) local j,x,b;
b:=convert(n,base,2); x:=g;
for j from nops(b)-1 to 1 by -1 do
x:=mult(x,x); if b[j]=1 then x:=mult(x,g) fi;
od; x; end;
fastexp(2,11,(x,y)->x*y);
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
6.2.10. Diffie-Hellmann-Merkle-kulcscsere.
with(numtheory);
q:=safeprime(43598760126543278905668798765412345657890987654234186);
p:=(q-1)/2; isprime(p); g:=3;
T:=convert(floor(time()*1000)+3141592 mod (111^3),base,111);while nops(T)<3 do T:=[op(TT),0] od;
N:=3; T:=vector(N+3,T); n:=0; m:=0; c:="a";
nexttime:=proc() local i,S; global T,TT,N,m,n,c;
S:="0123456789-abcdefghijklmnopqrstuvwxyz";
m:=1+(T[3+n] mod 3);
i:=T[m] mod 37;
if S[i+1]=c then
n:=n+1; T[3+n]:=floor(time()*1000) mod 3*37*16; T[m]:=T[3+n]
fi;
if n=N then print(T); return fi;
m:=1+(T[3+n] mod 3);
i:=T[m] mod 37;
print(T,S[i+1]);
c:=readline(terminal);
while true do i:=0 od;
end;
nexttime();
convert(T,list); %[4..N+3]; map(t->t mod 16,%);
x:=add(%[i]*16^(i-1),i=1..nops(%)); X:=g&^x mod q;
x:=76813406921544738654231750679890923210164916436739; X:=g&^x mod q;
y:=47614360991784651324765987666789098766542333432543; Y:=g&^y mod q;
X&^y mod q; Y&^x mod q;
6.2.29. Megjegyz\303\251s.
*6.2.41. A Miller-Rabin-f\303\251le val\303\263sz\303\255n\305\261s\303\251gi teszt.
millerrabin:=proc(n::posint,a::posint) local j,k,q,b;
if n=2 or n=3 or n=5 or n=7 then return true fi;
if n<9 then return false fi;
b:=a mod n; if b=0 or b=1 then return FAIL fi;
k:=0; q:=n-1; while type(q,even) do k:=k+1; q:=q/2; od;
b:=b&^q mod n; j:=0; if b=1 then return true fi;
while j<k do if b=n-1 then return true fi; b:=b^2 mod n; j:=j+1; od;
false; end;
millerrabin(9,2); millerrabin(11,2);
for n do if millerrabin(n,2)<>isprime(n) then print(n) fi; od;
for n do if millerrabin(n,2)<>isprime(n) and millerrabin(n,3)<> isprime(n) then print(n) fi; od;
n;
6.2.43. Feladat: \303\241lpr\303\255mek.
6.2.44. Feladat: Carmichel-sz\303\241mok.
6.2.51. Tov\303\241bbi feladatok megold\303\241sokkal.
6.2.52. Tov\303\241bbi feladatok.
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
6.4. L\303\241nct\303\266rtek
restart; with(numtheory);
*6.4.12. P\303\251lda.
nextrangecfrac:=proc(L::list) local a,a1,a2,j,q1,q2; j:=nops(L);
if j=0 then return FAIL fi; a:=L[j];
a1:=op(1,a); a2:=op(2,a); q1:=floor(a1); q2:=floor(a2);
if q1<>q2 then return L fi;
[op(L[1..j-1]),q1,1/(a2-q2)..1/(a1-q1)] end;
[314159265/10^8..314159266/10^8]; nextrangecfrac(%); nextrangecfrac(%); nextrangecfrac(%); nextrangecfrac(%); nextrangecfrac(%); nextrangecfrac(%);
evalf(355/113);
cfrac(Pi,100,quotients);
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
6.4.13. Intervallumaritmetika.
*6.4.28. Tov\303\241bbi feladatok megold\303\241sokkal.
*6.4.29. Tov\303\241bbi feladatok.
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn