pepeprepa wrote:I don't follow your formula Chase, where does it come from?
I did it by calculation, it's ok for the timing, but can be complicated if there are more numbers.
I used two formulas in my post.
First formula is to find the number of integers.
How many integers are there between 1-1000 that are divisible by 8
first integer =8 (first integer divisible by 8)
last integer = 1000 (last integer multiplied by 8)
[1000-8]/8 = 124 + 1 (we need to add 1 because we have subtracted 8.
Therefore there are 125 integers between 1 and 1000 that are divisible by 8.
Second formula is to find the sum of integers.
What is the sum of all the integers between 1-1000 that are divisible by 8
n = no. of integers i.e. 125 from the above calculations
a= first term i.e. 8 (we find the sum of multiples of 8, therefore the first term would be 8 and not 1)
d= common difference between each term i.e. 8
The formula is n/2[2a+(n-1)d]
125/2[2*8 + (125-1)8]
= 125/2[16+992]
=125/2[1008]
= 125 * 504 = would be the answer.
I used such big numbers to show that both the formulas can work with any possible numbers.
Hope this helps. Let me know your thoughts.