On Mon, Apr 21, 2014 at 11:21 PM, Ivan Ivanivich <ivriabtsov at gmail.com> wrote: > if "basis" is 15, then "mod" == 0 twice - when the "divider" is 3 and 15 Good! Yes, you worked out exactly what the problem is. :) There are ways to simplify your code, but it's now giving the correct result, so that's the most important thing. ChrisA