MKLab
Chicken McNugget Theorem explained - Printable Version

+- MKLab (https://mklab.gr)
+-- Forum: [INDEX] (https://mklab.gr/forumdisplay.php?fid=1)
+--- Forum: MATHEMATICS (https://mklab.gr/forumdisplay.php?fid=3)
+---- Forum: ARTICLES (https://mklab.gr/forumdisplay.php?fid=13)
+----- Forum: NUMBER THEORY (https://mklab.gr/forumdisplay.php?fid=148)
+----- Thread: Chicken McNugget Theorem explained (/showthread.php?tid=1543)



Chicken McNugget Theorem explained - mklabgr - 08-10-2026

Chicken McNugget Theorem explained

Summary

The Codeforces article explains the Chicken McNugget Theorem, a useful result in number theory for determining which integers can be expressed as nonnegative combinations of two relatively prime positive integers $m$ and $n$. It states that the largest integer that cannot be written as $am+bn$ is $mn-m-n=(m-1)(n-1)-1$, where $a,b\ge0$, and that every larger integer can be represented in this way. It also gives the number of positive integers that cannot be represented as exactly $\frac{(m-1)(n-1)}{2}$. 

For example, using $m=2$ and $n=5$, the impossible values are $1$ and $3$, while every integer greater than $3$ can be formed. The theorem is particularly useful in competitive programming problems such as Codeforces 1526B – I Hate 1111, where recognizing this mathematical structure can replace a more complicated approach. 

ARTICLE