Integer manipulation, modular arithmetic, and number-theoretic problem solving.
Math problems test working with numbers directly. Key ideas include digit manipulation, overflow detection, fast exponentiation, and cycle detection.
Digit operations O(log n) · Fast power O(log n)
Usually O(1)
Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.
n % 10 gets last digit, n / 10 removes it
check bounds before multiplying
binary exponentiation O(log n)
mathematical sequences often cycle (Happy Number)
Euclidean algorithm: gcd(a, b) = gcd(b, a % b)
Sieve of Eratosthenes for all primes up to n