Fermat theorem (Fermat theory) is an important theorem in number theory: if P is prime, and gcd (a,p) = 1, then a(p-1) ≡1 (mod p). That is: If A is an integer, p is a prime number, and A,p coprime (that is, there is only one convention of 1), then the remainder of a (p-1) divided by P is constant equal to 1.
The extended Euclidean algorithm is used to solve a set of X, y in known a, b to satisfy the Bézout equation: ax+by = gcd (A, B) =d (the solution must exist, according to the correlation theorem in number theory). Extended Euclidean is commonly used in solving linear equations and equations.
Euclidean algorithm expands the Euclidean algorithm not only calculates (a, b) the greatest common divisor, but also can calculate the multiplication inverse of a-and B-mode A, in C language is described as follows:
1int gcd (intAintBint&ar,int&BR)2 {3 intx1,x2,x3;4 intY1,y2,y3;5 intT1,t2,t3;6 if(0==A)//There is a number of 0, there is no multiplication inverse7 {8Ar=0; br=0;9 returnb;Ten } One if(0==b) A { -Ar=0; br=0; - returnA; the } -x1=1; x2=0; x3=A; -y1=0; y2=1; y3=b; - intnk; + for(t3=x3%y3;t3!=0; t3=x3%y3) - { +k=x3/Y3; At2=x2-k*y2;t1=x1-k*Y1; atx1=y1;x2=y2;x3=Y3; -y1=t1;y2=t2;y3=T3; - } - if(y3==1)//There are multiplication inverse elements - { -Ar=Y2; inBr=X1; - return 1; to } + Else//number of Conventions not 1, non-multiplicative inverse - { theAr=0; *Br=0; $ returnY3;Panax Notoginseng } -}
000
Mathematics (1. Fermat theorem 2. Extended Euclidean algorithm 3. Momo inversion)