Congruence and Modular Arithmetic

Modular Multiplicative Inverse

Competitive Programming

Needed to learn this after messing up this question https://codeforces.com/contest/2008/problem/F

Resources

This is calculated using EEA.

int x, y;
int g = extended_euclidean(a, m, x, y);
if (g != 1) {
    cout << "No solution!";
}
else {
    x = (x % m + m) % m;
    cout << x << endl;
}

MATH135

Inverses in (INV )

Let be an integer with . The element in has a multiplicative inverse if and only if . Moreover, when , the multiplicative inverse is unique.

Inverses in (INV )

For all prime numbers and non-zero elements in , the multiplicative inverse exists and is unique.