Math
GCD, primes, modular arithmetic, fast powers, digit tricks, and counting — formulas that replace loops.
This topic is part of Pro.
Free covers the C and Python courses, the first three DSA topics, the opening system design lessons and the beginner AI lessons, all with the full coach. Pro opens the rest of the library in the FollowtheDamnCode app.
What is in it
- 1GCD and primesEuclid's algorithm in O(log n), trial division to √n, and the sieve for every prime below n. Pro
- 2Modular arithmetic and fast powerKeep numbers small with "mod 10⁹ + 7" at every step, and compute xⁿ in O(log n) by squaring. Pro
- 3Working with digitsPeel digits with % 10 and // 10, rebuild numbers, detect cycles, and convert Roman numerals. Pro
- 4Counting and combinatoricsPermutations, combinations, Pascal's triangle, and computing n choose k without overflow. Pro