27.12.2012 Views

Introducción a la teoría de números. Ejemplos y - TEC-Digital

Introducción a la teoría de números. Ejemplos y - TEC-Digital

Introducción a la teoría de números. Ejemplos y - TEC-Digital

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

138 ALGORITMOS PARA EL MCD<br />

positivos. Se necesitan tres variables: c para el nuevo divi<strong>de</strong>ndo, d para el nuevo divisor y r<br />

para el resto (positivo). La función que calcu<strong>la</strong> q <strong>la</strong> l<strong>la</strong>mamos cquo, es <strong>de</strong>cir, q=cquo(a,b). La<br />

función que calcu<strong>la</strong> el resto positivo <strong>la</strong> l<strong>la</strong>mamos crem, r=crem(a,b).<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

Algoritmo 8.1: Máximo común divisor: Algoritmo <strong>de</strong> Eucli<strong>de</strong>s<br />

Datos: a, b ∈ Z, b �= 0.<br />

Salida: mcd(a,b)<br />

if a = 0 then<br />

return mcd(a,b) = b<br />

c = a, d = b;<br />

while d �= 0 do<br />

r =crem(c,d);<br />

c = d;<br />

d = r;<br />

return mcd(a,b) = c;<br />

Ejemplo 8.2 Veamos como funciona el algoritmo, calcu<strong>la</strong>mos mcd(89,144),<br />

mcd(89,144) = 1.<br />

c<br />

144 =<br />

↙<br />

c<br />

89 =<br />

↙<br />

c<br />

55 =<br />

↙<br />

c<br />

34 =<br />

↙<br />

d<br />

89 ·1+ crem(c,d)<br />

55<br />

d<br />

55 ·1+ crem(c,d)<br />

34<br />

d<br />

34 ·1+ crem(c,d)<br />

21<br />

d<br />

21 ·1+ crem(c,d)<br />

13<br />

.<br />

c 2 = d 1 ·2 + 0<br />

Implementación. La función crem necesita <strong>la</strong> función cquo.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!