Simple number theory summarizing 2--equation and extended Euclidean algorithm

Source: Internet
Author: User
Tags gcd

After the last summary of the pigeon has not long in fact is about to start school hurriedly to the liver two articles

Today's content--congruence equation and extended Euclidean algorithm

Co-yu

Congruence definition: If there are two integers, a, a, so that (a-B) mod p is 0, then the "a" is the case with the mod p

In other words, a mod p is equal to the B mod p

Record as \ (a\equiv B (mod P) \)

For integer a,b,c and natural number M,n

Congruence has the following properties:

    1. Reflexivity: \ (a\equiv a (mod P) \)
    2. Symmetry: if present \ (a\equiv B (mod p) \), then \ (b\equiv A (mod p) \)
    3. transitivity: if present \ (a\equiv B (mod p) \), \ (b\equiv C (mod p) \), then \ (a\equiv B (mod p) \)
    4. Same additive: if \ (a\equiv B (mod p) \), then \ ((a+c) \equiv (b+c) (mod p) \)
    5. Multiplicative sex 1: if \ (a\equiv B (mod p) \), then \ ((a*c) \equiv (b*c) (mod p) \)
    6. Multiplicative sex 2: if \ (a\equiv B (mod p) \), \ (c\equiv d (mod p) \), then \ ((a*c) \equiv (b*d) (mod p) \)
    7. Idempotent: if \ (a\equiv B (mod p) \), then \ ((a^c) \equiv (b^c) (mod p) \)

Thus, we can get two inferences.

    1. \ ((a*b) mod k = (a mod k) * (b mod k) mod k \)
    2. If \ (a mod p = x, a mod q = x,p, q coprime, then a mod p*q =x \)

But, believe in me as wise as you also found a problem, yes, the same as not satisfied with the removal of sex, that is not satisfied if \ (a\equiv B (mod p) \), then \ ((A/C) \equiv (b/c) (mod p) \)

So how to solve the division of the mold, bald and clever mathematicians also found this problem, using inverse knowledge, we can solve the problem!

But inverse yuan, I decided to say next time, actually is the Pigeon (Goo Cuckoo)

Extended Euclidean algorithm

Euclid's algorithm believes everyone already knows qwq.

is to seek the GCD method of dividing

Do not know can go to see my previous article (righteously cheat traffic qwq)

So what is the extended Euclidean algorithm? (Black question mark. jpg)

The extended Euclidean algorithm uses the iterative process in Euclid's algorithm to make it possible to find the application of equations such as \ (ax + by = gcd (A, b) \)

We can simply prove and sensibility to understand the correctness of the extended Euclidean algorithm:

  

First, when the Euclidean algorithm stops iterating

In this case \ (a=1,b=0, at this time, gcd (A, b) =x,ax+by = GCD (A, B) is clearly established \)

In the course of an iteration

There \ (b{x} ' + (a mod b) {y} ' = gcd (b, a%b) \) with \ (ax + by = gcd (A, b) \)

Is launched from the previous layer

\ (x= {y} ' \), \ (Y={x} '-a/b*{y} ' \)

It can then be pushed to the initial condition to obtain the solution

  

The following shows the implementation of the Code

intEXGCD (intAintBint&x,int&y) {    if(b = =0) {x=1; Y=0; returnA; }    intAns = EXGCD (b, a%b, x, y); intt =x; X=y; Y= t-a/b *y; returnans;}

That's it, meow.

Application of the extended Euclidean theorem

Using the extended Euclidean theorem, we can solve problems like \ (Ax+by = c \)

When \ (c \mid gcd (A, b) \), there is an integer solution to the indeterminate equation of \ (Ax+by = c \)

Therefore, the original variant of \ (Ax+by = d (d = gcd (a)), the form of the extended Euclidean theorem to solve the equation of a set of solutions \ ((x, y) \), and then multiply it by \ (\frac{c} {gcd (A, B)} \)

The solution of the original equation can be solved! (quickly praise me. jpg)

To solve the solution of extending Euclidean theorem

As the linear indefinite equation with the form such as \ (Ax+by = c \) has infinitely many solutions, it is not necessarily guaranteed to find the smallest positive integer solution in the process of extending Euclid theorem, we have the following way

Easy to launch, for linear indefinite equations \ (Ax+by = c \), there is a set of solutions \ (x,y\) with another set of solutions \ (* (x + \frac {a*t} {gcd (A, B)}), b* (Y-\frac {b*t} {gcd (A, b)} | (T\in \mathbb{z})) \) are the solutions of the original equation

Then the method can be obtained: for linear indefinite equation \ (Ax+by = c \), its minimum positive integer solution is (\ (x= () (x\%t) +t), (\%t (b)) \), \ (T=B/GCD (((y=) y\%t), (+t ((b))) )

At this point, the problem has been solved

Simple number theory summarizing 2--equation and extended Euclidean algorithm

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.