Replace a hand-coded leading one counting loop with the magic from MathExtras.h.