The math that contest problems assume without naming it. Each fact is short; the skill is noticing which one applies.
Floor, ceiling and division
long long floorDiv(long long a, long long b) { return a / b - ((a % b != 0) && ((a < 0) != (b < 0))); }
long long ceilDiv(long long a, long long b) { return a / b + ((a % b != 0) && ((a < 0) == (b < 0))); }
long long modFloor(long long a, long long m) { return ((a % m) + m) % m; } // m > 0, result in [0, m)| Identity | Condition |
|---|---|
| , | |
| , | |
| real | |
| , with | |
| takes at most distinct values | see Floor Sums |
| divisor counting |
Proof: the floor identities
Ceiling. Write with . If , both sides equal . Otherwise and with , so the floor is . Nested floor. Let , so . Let , so . Then and , so . Sum of floors. With , and . The helpers were tested against floating-point division for all , .
Inequalities
| Inequality | Statement | Equality |
|---|---|---|
| AM–GM | for | all equal |
| Cauchy–Schwarz | proportional vectors | |
| rearrangement | is maximal when both are sorted the same way | — |
| Jensen | for convex | all equal or linear |
| triangle | $ | a + b |
| Bernoulli | for , | or |
| harmonic bound | — |
Proof: AM–GM and Cauchy–Schwarz
Cauchy–Schwarz. The quadratic is non-negative for all real , so its discriminant is : . AM–GM. is concave, so by Jensen for positive (zeros make the right side ); exponentiate. Jensen for two points is the definition of convexity, and it extends to points by induction, writing the mean of points as a weighted mean of one point and the mean of the other .
Sums and sequences
| Sum | Closed form |
|---|---|
| , , | , , |
| geometric | (); modulo use an inverse or a doubling recursion |
| for $ | |
| telescoping | ; e.g. |
| arithmetic progression mod | period |
| linear recurrence | characteristic roots, matrix power (Matrix Power) |
Proof: power sums and the geometric series
Each formula is checked at and by induction: adding the next term to the right side gives the formula at (for : ). For the geometric series, by telescoping.
Modular and counting observations
| Observation | Use |
|---|---|
| squares are and (odd squares ) | impossibility of sums of squares |
| digit sum | digit problems |
| ; for | Fermat-style simplifications |
| pigeonhole on prefix sums mod | some subarray sum divisible by |
| double counting | count pairs (element, set) both ways |
| stars and bars | distribute identical items |
| bijections | count an easier set of the same size |
More: Modular Arithmetic, Counting Fundamentals, Invariants.