Calculating the number of integers divisible by 8

The problem is that both endpoints of the interval $[10000, 70000]$ are divisible by $8$, while neither endpoint of the interval $[1, 60001]$ is divisible by $8$.

Your first method is correct. It works since both endpoints are divisible by $8$.

In your second method, your interval should start at $0$ and end at $60,000$ so that both endpoints are again divisible by $8$. You then have to add $1$ to account for the fact that $0$ is divisible by $8$. Observe that $$\left\lfloor \frac{60000 - 0}{8} \right\rfloor + 1 = 7501$$


If you want a catch-all formula for the number of multiples of $n>0$ in $[a,b]$, you may use $$\left\lfloor \frac bn\right\rfloor-\left\lceil\frac an\right\rceil+1,$$

which essentially comes from the consideration that the map $x\mapsto nx$ defined on the integers in $\left[\left\lceil\frac an\right\rceil,\,\left\lfloor \frac bn\right\rfloor\right]$ is bijective onto the set of multiples of $n$ in $[a,b]$. In a number of instances the nuance of where to divide and where to take floor or ceiling is obscured by other facts.


Your second method, generalized to the interval $[a,b],$ appears to be $$\left\lfloor \frac{b - a + 1}8\right\rfloor.$$

The floor function gives you an integer, which you want, but it does this simply by throwing out any fractional part. When you use a formula like $$\left\lfloor \frac x8\right\rfloor,$$ you get zero for the first seven positive values of $x$. You don't get a positive result until $x \geq 8.$

Consider the simpler problem of counting multiples of $8$ in the set $[10000, 10000].$ There is one element in that set and it is a multiple of $8$, so the answer should be $1,$ but $$\left\lfloor \frac{10000 - 10000 + 1}8\right\rfloor = \left\lfloor \frac 18\right\rfloor = 0.$$ You'll get the same wrong answer for $[10000,10001],$ $[10000,10002],$ $[10000,10003],$ $[10000,10004],$ $[10000,10005],$ and $[10000,10006].$

For $[10000,10007],$ you get $$\left\lfloor \frac{10007- 10000 + 1}8\right\rfloor = \left\lfloor \frac 88\right\rfloor = 1,$$ which is finally a correct answer. But for $[10000,10008]$ you still get only $1$ from the formula while the correct answer is $2.$

The problem is that your formula only counts every eighth integer, but your interval has a multiple of $8$ at the first integer. The only time the formula is correct is just before you reach the next multiple of $8,$ because that's the only time you can partition the set of integers into subsets with exactly $8$ integers in each subset and exactly one multiple of $8$ in each subset.

If your set started at $10001$ instead of $10000$ the formula would work fine, because the first seven integers starting at $10001$ are not divisible by $8$ and you only get a multiple of $8$ at the eighth integer added to the set.

The catch is that in general, in order to know how many multiples of some integer $n$ are in a set of consecutive integers it is not enough to know how many integers are in the set. The only time this information is sufficient is when the number of integers is an exact multiple of $n$. In any other case you need to know where the sequence starts (at least relative to the nearby multiples of $n$) in order to know whether there is an "extra" multiple of $n$ in the numbers that are left over after you have partitioned the rest of the numbers into subsequences of $n$ numbers each.