Problem. Nuggets come in packs of and with . What is the largest amount you cannot buy, and how many amounts are impossible?
Answer: the largest is (Sylvester), and there are impossible amounts. With packs the largest impossible amount is .
long long frobenius(long long a, long long b) { return a * b - a - b; } // gcd(a, b) = 1
long long gapCount(long long a, long long b) { return (a - 1) * (b - 1) / 2; } // non-representable amountsProof: Sylvester's formula and the gap count
Every integer has a unique representation with (since is invertible mod ); is representable with non-negative coefficients iff that . For , the representation is , , so it is not representable; for any larger , the unique gives , so . Count. The map sends representable to non-representable numbers and vice versa on (if both were representable, their sum would be), so exactly half of these numbers are impossible. Checked by a DP for all coprime . More than two pack sizes: shortest paths modulo the smallest pack (Congruences).