Math -> Modular Arithmetic
Safe modular computation: powers, inverses, congruences, and the algebra needed to avoid overflow and mistakes.
- Topic slug:
math/modular-arithmetic
- Tutorial page: Open tutorial
- Ladder page: Open ladder
- Repo problems currently tagged here:
4
- Repo companion pages:
2
- Curated external problems:
8
Microtopics
- modpow
- modinv
- Fermat
- Euler-theorem
- congruences
- mod-division
Learning Sources
Practice Sources
Repo Companion Material
Curated External Problems
Core
| Problem |
Source |
Difficulty |
Context |
Style |
Prerequisites |
Tags |
Why it fits |
| Exponentiation |
CSES |
Easy |
Fast-Exponentiation, Mod Arithmetic |
Implementation; Math |
Modular Arithmetic; Binary Exponentiation |
Binary Exponentiation; Pow |
Canonical modular fast-power warmup. |
| Distributing Apples |
CSES |
Easy-Medium |
Stars And Bars, Mod Arithmetic |
- |
- |
Combinations; Distributions |
Simple counting with modular binomial coefficients. |
| Binomial Coefficients |
CSES |
Medium |
Combinatorics/Counting-Basics, Mod Inverses, Combinatorics |
Math; Precomputation |
Factorials; Modular Inverse; Combinations |
Ncr; Factorials; Modular Inverse; Inverse Factorials |
Standard modular combinations with precomputation. |
| Creating Strings II |
CSES |
Medium |
Factorials, Mod Inverses |
- |
- |
Multiset Permutations; Combinatorics; Mod Arithmetic |
Distinct-string counting via modular combinatorics. |
| Exponentiation II |
CSES |
Medium |
Fast-Exponentiation, Mod-Inverse, Totient Tricks |
Implementation; Number Theory |
Binary Exponentiation; Modular Arithmetic; Fermat's Little Theorem |
Tower Exponentiation; Fermats-Little-Theorem; Mod Arithmetic; Phi |
Adds exponent towers and modulus reduction logic. |
Stretch
| Problem |
Source |
Difficulty |
Context |
Style |
Prerequisites |
Tags |
Why it fits |
| Counting Grids |
CSES |
Hard |
Combinatorics/Bracelet-Counting |
Combinatorics; Algebra |
Modular Arithmetic; Symmetry Counting |
Burnside; Pólya Counting; Mod Arithmetic |
A stronger symmetry-counting problem that rewards comfortable modular evaluation. |
| Counting Necklaces |
CSES |
Hard |
Combinatorics/Burnside |
Combinatorics; Number Theory |
Modular Arithmetic; Group Actions; GCD/LCM Basics |
Burnside; Group Actions; Mod Arithmetic |
A canonical advanced counting problem where modular arithmetic sits inside Burnside's lemma. |
| Graph Paths I |
CSES |
Hard |
Matrix-Exponentiation |
Graphs; Math |
Modular Arithmetic; Matrix Multiplication; DP On Walks |
Graph Walks; Mod Arithmetic |
A classic matrix-exponentiation application where the answer is required modulo a prime. |
Repo Problems
| Code |
Title |
Fit |
Difficulty |
Pattern |
Note |
Solution |
COUNTINGNECKLACES |
Counting Necklaces |
secondary |
hard |
burnside lemma; rotation symmetry; orbit counting |
Note |
Code |
DISTRIBUTINGAPPLES |
Distributing Apples |
secondary |
medium |
stars and bars; single binomial query; factorial precompute |
Note |
Code |
EXPONENTIATION |
Exponentiation |
primary |
easy |
binary exponentiation; repeated squaring; modular fast power |
Note |
Code |
EXPONENTIATION2 |
Exponentiation II |
primary |
medium |
binary exponentiation; fermat exponent reduction; zero exponent edge case |
Note |
Code |
Regeneration
python3 scripts/generate_problem_catalog.py