# Counting the number of element in a range of integers

I have a problem related to counting the number of integers in a range $[a,b]$.

In particular, my problem is related to the counting of elements in a finite sequence of numbers $(s_1, \cdots, s_n)$, such that, given the $i$th number in the sequence, result $$s_i \in [a,b]$$ and $$s_i-s_{i-1}=s$$ where $s$ is a known fixed number and obviously is set $s_1=a$.

Exists a formula capable of counting the number of elements?

EDIT

In other words, what is the value of $n$?

Simply, given three integers $a$, $b$ and $s$ such that $a<b$ and $s>1$, then the number $n$ is:

$$n=\lfloor \,\,[(b-a)+1]/s \,\rfloor$$

Well, the greatest integer in the range will be $\lfloor b\rfloor,$ and the least integer in the range will be $\lceil a\rceil,$ so there will be $1+\lfloor b\rfloor-\lceil a\rceil$ integers in the interval $[a,b],$ or alternately $1+\lfloor b\rfloor+\lfloor-a\rfloor.$
• This is true if $s=1$, when $s\geqslant2$ that number is wrong. Jun 3, 2013 at 11:08
• The requirement $s_1=a$ was by no means obvious. Glad you figured it out, though. Jun 3, 2013 at 11:28
• Yes, you are right_ $s_i \in [a,b]$ doesn't mean that $s_1 = a$. I was wrong! I can't upvote, actually: get a virtual +1 from me! Jun 3, 2013 at 11:30
I don't quite understand you. If you know the $i$th number and you know the difference between two consecutive number, what you need to do is to add $i$th number with the difference $s$ to get the $(i+1)$th. So what' wrong? And this is a arithmetic progression. If you know the $i$th element, $s_{i}$, and the difference $s$, the fomula for $n$th general term is given by $$s_{i}+(n-i)s$$. Then you can calculate the largest number that is in $[a,b]$.
• I don't have a problem in generating the sequence, I have a problem in counting the total numbers in the sequence. In particular, I would not generate the sequence bu only use a formula. E.g., if $s=1$, then the sequence has $(b-a)+1$ elements, what happens when $s\geqslant2$? Exists any formula? In other words, what the value of $n$ is? Jun 3, 2013 at 11:10