Usage: Used for division modulo
Idea: expanding Europe
Requirements: B, p coprime
Multiply inverse of k to B:
When solving the problem of division modulus:
Have (A/b)%p = (a*k)%p
When B is large, there is a precision problem with division. So
Multiplication Inverse:
If B*k≡1 (mod p)
Then the k is the multiplication inverse of the B about P
We can use the B to multiply the inverse k of p, multiply a by the K-mode p, i.e. (A * k) mod p. The result is equivalent to (A/b) mod p.
Certificate
Because b * k≡1 (mod p)
Then there is b * k = p*x+1
Get k = (P * x+ 1)/b
Substituting k into (A * k) mod p
Get:
(A * (p * x + 1)/b) MoD p
= ((A * p * x)/b +/a) mod p
=[((A * p * x)/b) mod p + (A/b)] mod p
=[(P * (A * x)/b) mod p + (/A/b)] mod p
= (0 + (A/b)) mod p
= (A/b) mod p
using Euclidean expansion to seek inverse meta-requirements gcd (b, p) = = 1
The multiplication inverse can be extended by Euclidean:
void Euild (ll A, ll B, LL &x, LL &y)//x is a multiplicative inverse of b
{
if (0 = = b) {
x = 1, y = 0;
return;
}
Euild (b, a%b, x, y);
ll flag = x;
x = y;
y = flag-a/b * y;
}
Multiplication inverse element of number theory learning