0
$\begingroup$

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$?

ANSWER

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 $$

$\endgroup$

2 Answers 2

1
$\begingroup$

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.$

$\endgroup$
4
  • $\begingroup$ This is true if $s=1$, when $s\geqslant2$ that number is wrong. $\endgroup$
    – mat_boy
    Jun 3, 2013 at 11:08
  • $\begingroup$ However, you was very close. I attached the right answer to my question. $\endgroup$
    – mat_boy
    Jun 3, 2013 at 11:24
  • $\begingroup$ The requirement $s_1=a$ was by no means obvious. Glad you figured it out, though. $\endgroup$ Jun 3, 2013 at 11:28
  • $\begingroup$ 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! $\endgroup$
    – mat_boy
    Jun 3, 2013 at 11:30
0
$\begingroup$

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]$.

$\endgroup$
1
  • $\begingroup$ 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? $\endgroup$
    – mat_boy
    Jun 3, 2013 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.