From: "Joe Wölfel" Date: 2008-10-20T23:18:42+09:00 Subject: Re: Counting Right, as per my caveat n must be divisible by d*2. You can't divide 1000 by twelve. But 996 is divisible by 12. So you can use that for d instead for that particular case. If you played around with remainders for a bit you could adjust the formula I gave to work for all cases. The point is you go from linear time for all the iterative methods to constant time if you just work out a formula. For very large numbers the iterative methods will take more time than you are willing to spend and perhaps never finish at all. On 18 oct. 08, at 11:02, Craig Demyanovich wrote: > The OP needs multiples of 2 and 6. Since all multiples of 6 are also > multiples of 2, just checking for multiples of 6 suffices. However, > if d = > 6, your two approaches don't produce the same result. For d = 6, they > produce 83498 and 83166, respectively. 83166 is the correct answer, I > believe. > > Regards, > Craig