Generalize the optimization made for even numbers