European expansion board + Chinese remainder theorem board

 

About expansion of Europe:

I do not want to remember this board, so I pushed it again

Solving ax + by = c;

Shu Pei Theorem: ax + by = gcd (a, b) certain solvable

So if c% gcd! = 0 has no solution must

Multiplied with d / c a (d / c * x) + b (d / c * y) = d;

Solving answer multiplied by c / d is the original answer

Can be derived from Euclid

(b)x+(a%b)y==gcd(b,a%b)

a%b=a-(a/b)*b

According to the guidelines polynomial

ax+by=d

 

Therefore, x = y

y=x-(a/b)*y

Note should be written ex_gcd (b, a% b, y, x) // x = y

y=x-(a/b)*y

 

Well on the board

code:

ll ex_gcd(ll a,ll b ,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        ex_gcd(b,a%b,y,x);
        y=y-(a/b)*x;
    }
    return x;
}

 

Chinese remainder theorem:

 

 

 

The smallest integer solution:

x = (a1*M1*inv(M1) + a2 * M2 * inv(M2) + .... + ai * Mi * inv(Mi) + ... + ak*Mk*inv(Mk))%M;

Where: Mi = M / mi; INV (Mi) is the modulus mi Mi inverse element.

 

Inversion _> Euclid expand enough

Modulus Fermat's Little Theorem must be a prime number

Guess you like

Origin www.cnblogs.com/OIEREDSION/p/11297658.html