Injective, Surjective, and Bijective
Reflexive, Symmetric, and Transitive
Associative, Commutative, and Distributive
Reflexive, Antisymmetric, and Transitive
%
-17 % 5
-2
a
m
[0, m-1]
(a % m + m) % m
abs(a % m)
a % m
(a + m) % m
b
Calculate (a % m) * (b % m) and store it in a long long.
(a % m) * (b % m)
long long
Use long long and calculate (1LL * a * b) % m.
(1LL * a * b) % m
Use the formula ((a % m) + (b % m)) % m.
((a % m) + (b % m)) % m
Use int and calculate (a * b) % m directly.
int
(a * b) % m
When m is a prime number.
When a and m are coprime (i.e., gcd(a, m) = 1).
gcd(a, m) = 1
The inverse always exists.
When a < m.
a < m
Extended Euclidean Algorithm
Sieve of Eratosthenes
Binary Search
Fermat's Little Theorem
(a(modm))/(b(modm))(a \pmod{m}) / (b \pmod{m})(a(modm))/(b(modm))
(a(modm))×(bm−2(modm))(a \pmod{m}) \times (b^{m-2} \pmod{m})(a(modm))×(bm−2(modm)) for any m.
(a(modm))×(b−1(modm))(a \pmod{m}) \times (b^{-1} \pmod{m})(a(modm))×(b−1(modm)), where b−1b^{-1}b−1 is the modular multiplicative inverse of b.
O(b)O(\sqrt{b})O(b)
O(1)O(1)O(1)
O(b)O(b)O(b)
O(logb)O(\log b)O(logb)
p
The inverse is ap−2a^{p-2}ap−2.
The inverse is ap−1a^{p-1}ap−1.
The theorem cannot be used to find inverses.
The inverse is p−ap-ap−a.
False
True
Solving systems of simultaneous linear congruences.
Determining if a large number is prime.
Finding the greatest common divisor of two very large numbers.
Calculating large exponents under a single prime modulus.
the number of congruences must be a power of two.
all the moduli n_i must be prime numbers.
n_i
all the remainders a_i must be the same.
a_i
the moduli n_i must be pairwise coprime.
x
5
8
9
11
All done? Get your grade