For positive integers A and B, a maximum common factor can be obtained by Euclidean algorithm, and the improved algorithm satisfies the maximum common factor q=xa+yb.
So how do we find A and B?
That's what the book says. So we use the code to get him out, to recommend a book "The Art of Computer.programmer," the first part of the math is really boring the way I choose is appropriate swallowed for this, but for the algorithm described in it is still to Take a closer look at the drip.
For the analysis of the algorithm I go directly to the original book map
#include "stdafx.h"//expanded Euclidean algorithm//For a positive integer A, b has m*a+n*b=r //r for Greatest common divisor this is the improved Euclidean algorithm int _tmain (int argc, char** Grav) { int m = $, n = 255;int r;int t;int x = 0, x1 = 1, y1 = 0, y = 1;while ((r = m%n)! = 0) { //change x x1t = x1;x 1 = x;x = t-(int) (m/n) *x; Change y y1t = y1;y1 = Y;y = t-(int) (m/n) *y; Change m<-n n<-rm = N;n = r;} printf ("x=%d,y=%d, remainder =%d", x,y,n); return 0;}
An improved Euclidean algorithm----the Novice learning algorithm