vitorcbarbieri
I did it in a more ''muscle'' way:
For the remainder to be 3 when divided by 16, must follow the equation:
3+16*n (n is integer)
n=0 -> 3
n=1 -> 19
Whats in biggest n, that the result of the equation is smaller than 1.000 (inclusive)?
Let the +3 aside for a bit..
16*10 = 160
16*20 = 320
16*40 = 640
16*60 = 640+320 = 960
16*61 = 976
16*62 = 992 (enough) + 3 = 995 (last number that follows the equation)
Answer: 62 + (n = 0) option = 63 possibilities
What you guys think?
vitorcbarbieriI think you found an approach with a smart pattern that works! It is a bit similar to mine, above.
I do not think your approach is "brute force" except maybe in one place where, had the upper limit of the range been an ugly number, you might have been calculating for awhile.
I didn't use round multiples of 10, times 16, to "multiply up" to the highest term. Maybe that is faster. It is certainly smart. Next time, if numbers aren't bad, I'll try your way. Just one tiny cautionary thought . . .
If you were to get some heinous number, say 173,619, as the last of the range, you might be multiplying for awhile, even if you used thousands, hundreds, and then tens. In a case such as that, to find multiples, you may want to try the reverse: divide the heinous number by the multiple to get the greatest number that "n" in 16n can be.
In other words: to find the highest multiple of 16 close to but less than 1,000: divide 1000 by 16 to get 62.xx.
It's 62.5, but I didn't calculate that. The second I saw I had a decimal coming, I just noted the .xx. Then I took the integer, 62, and multiplied by 16 to give me that highest value, 992. Added 3. Done on that front (very similar to your conclusion). If this cautionary thought seems dumb, of course, ignore it.
In any event, nice work! Glad you posted. Kudos.