Number Theory Summary 2012-09-05

Source: Internet
Author: User
Tags greatest common divisor modulus

Relatively dull, a little bit number theory took a long time to figure out, a small summary.

① Greatest Common divisor (Euclidean method)

Function gcd (a,b:longint): Longint;

Begin

If B=0 then Gcd:=a

else GCD:=GCD (b,a mod b);

End

② least common multiple

LCM (A, B) *gcd (A, b) =a*b

LCM (A, B) =a*b/gcd (A, b);

③ primes table

Sieve method

④ Prime number Test

Miller-rabbin Test:

If present and n coprime positive integer A satisfies a^ (n-1) =1 (mod n) (Fermat theorem is pushed), then N is a pseudo prime number based on a. The base B (s), which is not more than n-1, is continuously selected to calculate whether b^ (n-1) =1 (mod n) is available each time.    If each time is established, it is almost possible to conclude that N is prime. (from the Contest of Algorithmic Arts and Informatics)

⑤ Extended Euclid

If D=GCD (A, B) then there must be X, y to make ax+by=d.

Function extended_gcd (A,b:longint;var x,y:longint): Longint;

var k:longint;

Begin

If B=0 then BEGIN

Extended_gcd:=a;

x:=1;y:=0;

End

ELSE begin

EXTENDED_GCD:=EXTENDED_GCD (b,a mod b,x,y);

K:=x;

X:=y;

y:=k-(a div b) *y;

End

End

⑥ Fast Power (non-recursive notation)

Function Pow (k,q:longint): Longint;

Begin

Pow:=1;

While q<>0 do

Begin

If q mod 2=1 then pow:=pow*k;

K:=k*k;

Q:=q Div 2;

End

End

⑦ linear modal equation

Solution Ax=c (mod b)

Ax+by=c

Set D=GCD (A, b);

The necessary and sufficient condition for an integer solution to the problem is C mod d=0

Make A=a ' *d, B=b ' *d

Then gcd (a ', B ') =1

The original equation can be converted to a ' x+b ' y=c/d

By extending Euclidean solution a ' x ' +b ' y ' = 1 to derive x ' and Y '

and X=x ' *c/d y=y ' *c/d

But this is just one of the set of solutions MoD b conditions all the Jiewei

xi=x0+i* (B/D) (i=1,2,3,.....,d-1) x0 for any solution

⑧ Linear mode equations

Solve a series of X=ai (mod bi) (2<=i<=n)

Consider the simple case first, n=2.

i.e. X=A1 (mod B1);

X=A2 (mod b2);

namely X=a1+b1*y1

X=a2+b2*y2

A1+b1y1=a2+b2y2-B1Y1-B2Y2=A2-A1

It's easy to transform into a linear mode equation.

Likewise made D=GCD (B1,B2);

The case of the non-solution of the linear equation Group (A2-A1) MoD d<>0

The same linear mode equation extends the value of y1,y2 by expanding Euclidean

The x=a1+b1*y1=a2+b1*y2 also solved the solution of two equations.

The minimum nonnegative integer solution for X is x= ((x mod LCM (B1,B2)) +LCM (B1,B2)) mod LCM (B1,B2);

Generalized to multiple equation sets

The two equations are combined, i.e., the x value of the two equations is Q,

The combined new equation is x=q (mod LCM (B1,B2));

All equations 22 are combined and eventually the final answer is reached.

⑨ Chinese remainder theorem

Also for a series of X=ai (mod bi) (and all bi 22 coprime)

X has a unique solution under the Die B1*b2...bn

B=b1*b2*......*bn

For each bi to find a pi,pi=b/bi

and Pi=1 (mod bi)

That is to solve Pi*xi+bi*yi=1, gcd (PI,BI) = 1, expand the Euclidean solution.

And the final answer is x=p1*x1* A1+p2*x2*a2+......+pn*xn*an

⑩ multiplication Inverse element

Ax=1 (mod b) x exists when and only if GCD (A, b) =1

X is the multiplication inverse of a

In general, when calculating the division of a modulo, it is converted to multiply the inverse of the divisor.

11. About calculating division on the modulo

By Fermat theorem, when a,p coprime a^p=a (mod p)--a^ (p-2) =a^-1 (mod p)

(1/a) mod p ie a^-1 mod p=a^ (p-2) (mod p) so I found (1/a) mod p

12. The modulus of processing is not prime and the division is processed

To pi^ci the modulus into the product of a

Processed separately

Merging the solutions with the Chinese remainder theorem

13. Euler functions

φ (n) is the number of coprime to n in a number less than or equal to N.

N=p1^q1*p2^q2*p3^q3*...*pk^qk (P is an inter-heterogeneous mass factor)

φ (n) =n* (1-1/P1) * (1-1/P2) * (1-1/P3) *...* (1-1/PK)

φ (n) is an integrable function if (a, b) =1 thenφ (AB) =φ (a) φ (b)

Euler's theorem: (A, a) =1 a^φ (b) =1 (mod b)

14. Approximate and

To the approximate and

A=p1^k1*p2^k2*...*pn^kn

S = (1+P1+P1^2+P1^3+...P1^K1) * (1+P2+P2^2+P2^3+....P2^K2) * (1+p3+ p3^3+...+ p3^k3) * .... * (1+PN+PN^2+PN^3+...PN^KN)

Number Theory Summary 2012-09-05

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.