Concepts7

βš™οΈAlgorithmIntermediate

Modular Arithmetic Pitfalls

Modular arithmetic is about working with remainders, but programming languages often return negative remainders, so always normalize with (a % MOD + MOD) % MOD.

#modular arithmetic#modular inverse#fermats little theorem+12
βˆ‘MathIntermediate

Harmonic Lemma

The Harmonic Lemma says that the values of \lfloor n/i \rfloor only change about 2\sqrt{n} times, so you can iterate those value blocks in O(\sqrt{n}) instead of O(n).

#harmonic lemma#integer division trick#block decomposition+12
βˆ‘MathIntermediate

Multiplicative Functions

A multiplicative function is an arithmetic function f with f(mn) = f(m)f(n) whenever gcd(m, n) = 1.

#multiplicative function#dirichlet convolution#mobius function+12
βˆ‘MathIntermediate

Euler's Totient Function

Euler's Totient Function Ο†(n) counts how many integers from 1 to n are coprime with n.

#euler totient#phi function#coprime count+12
βˆ‘MathIntermediate

Modular Inverse

A modular inverse of a modulo m is a number a_inv such that a Γ— a_inv ≑ 1 (mod m).

#modular inverse#extended euclidean algorithm#fermats little theorem+12
βˆ‘MathIntermediate

Euler's Theorem

Euler’s Theorem says that if a and n are coprime, then a raised to the power Ο†(n) is congruent to 1 modulo n.

#euler totient#euler theorem#modular exponentiation+12
βˆ‘MathIntermediate

Fast Exponentiation

Fast exponentiation (binary exponentiation) computes a^n using repeated squaring in O(log n) multiplications.

#binary exponentiation#fast power#modular exponentiation+11