13.07.2015 Views

제 2 ‚절 The Euclidean Algorithm

제 2 ‚절 The Euclidean Algorithm

제 2 ‚절 The Euclidean Algorithm

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

12 1 extGCD := proc(x, y)local extGCD pos, L;extGCD pos := proc(n, m)local r0 , r1 , r2 , s0 , s1 , s2 , t0 , t1 , t2 , q1 ;r0 := n ;r1 := m ;s0 := 1 ;s1 := 0 ;t0 := 0 ;t1 := 1 ;q1 := floor(evalf(r0 /r1 )) ;r2 := r0 mod r1 ;while 0 < r2 dos2 := s0 − q1 ∗ s1 ;s0 := s1 ;s1 := s2 ;t2 := t0 − q1 ∗ t1 ;t0 := t1 ;t1 := t2 ;r0 := r1 ;r1 := r2 ;q1 := floor(evalf(r0 /r1 )) ;r2 := r0 mod r1end do;[r1 , s1 , t1 ]end proc;if x = 0 and y ≠ 0 then L := [y, 0, 1]elif x ≠ 0 and y = 0 then L := [x, 1, 0]elif x < 0 and y < 0 then L := extGCD pos(−x, −y) ; L := [L 1 , −L 2 , −L 3 ]elif x < 0 and 0 < y then L := extGCD pos(−x, y) ; L := [L 1 , −L 2 , L 3 ]elif 0 < x and y < 0 then L := extGCD pos(x, −y) ; L := [L 1 , L 2 , −L 3 ]elif 0 < x and 0 < y then L := extGCD pos(x, y) ; L := [L 1 , L 2 , L 3 ]end if;printf(“%d=(%d*%d)+(%d*%d) \”, L 1 , L 2 , x, L 3 , y);Lend proc> A:=extGCD(-24524578924,24598245424);‘4=(1611284665*-24524578924)+(1606459211*24598245424)‘A := [4, 1611284665, 1606459211]

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

Saved successfully!

Ooh no, something went wrong!