# Number of integers between two "real" numbers

At first thought, the question might appear to be stupid but at least for me it isn't. Note that the question asks the number of integers between two "real" numbers.

For example:

Number of integers between $1.0$ and $3.1$ is two! Difference = $2.1$

Number of integers between $1.9$ and $3.1$ is two! Difference = $1.2$

Number of integers between $1.99 and 2.9$ is one! Difference = $0.91$

Number of integers between $1.0$ and $1.91$ is zero! Difference = $0.91$

Note that there is no pattern.

How can the number of integers between two real numbers be found?

*Accepting solutions which take different cases to solve the problem.

Optional - not related directly to the question (source of the problem):

Find the values of $a$, for which the quadratic expression $ax^2 + (a - 2)x -2$ is negative for exactly two integral values of $x$.

Of course, one who can spot that $-1$ is a root of the equation for any given value of the parameter $a$ can solve it without issues.

But what about in a general case where the root depends on the parameter itself?

My approach to solve the problem was as follows. Firstly, a has to be a positive integer if not, there would be infinitely many integers where the expression would turn out to be negative.

Since $a > 0$, the parabola would be open upwards (convex from bottom and concave from the top). The points were the graph intersects the $x$-axis are the roots of the equation. Any real value which lies between the roots when substituted in the expression would evaluate to a negative real number (obvious from the graph). Hence, the above problem reduces to finding number of integers between the roots (which can be real) of the equation.

This would mean, the answer to the question of finding the number of integers between two real numbers should be such that conditions can be imposed.

If $p(x, y)$ was the function which gives number of integers between two real numbers $x$ and $y$ then I should be able to write it in the form, $p(x) = 2$ and solve for the range of values of $a$ where it holds good. ($x$ and $y$ are given in terms of the parameter $a$)

• I'm copying JMoravitz's comment on why my answer $|\lfloor{x}\rfloor-\lfloor y \rfloor|$ is unsatisfactory: "As per his examples, we can see he means strictly between. " Jul 22, 2016 at 6:03
• Yes, I was about to comment but the answer was deleted. You can solve the problem in different cases separately. One case where both the limits are integers, another case where only one of them is an integer and the last case where both are non-integers. Jul 22, 2016 at 6:04
• Why do you put the word "real" in quotation marks? Are you an apprentice of Dr. Evil? Jul 22, 2016 at 6:30
• @AsafKaragila To hilight the main issue. If it were integers, people would mark this as a duplicate and maybe even down vote thinking its a stupid question. Jul 22, 2016 at 7:03
• Not sure what you mean by "no pattern". The number of integers is always either the integer below or above the difference. If the sum of the fractional parts of the difference and the first number add to more than one you take the integer above the difference. Otherwise the one below. That's a pattern. One that's formalized in the solutions. Jul 22, 2016 at 7:55

Without loss of generality, let the numbers be $x$ and $y$ with $x\leq y$. Let $f(x,y)$ denote the function of counting how many integers are strictly between $x$ and $y$.

$$f(x,y)=\begin{cases}0&\text{if}~\lfloor y\rfloor - \lfloor x\rfloor = 0\\ \lfloor y\rfloor - \lfloor x\rfloor-1&\text{if otherwise and}~y\in\Bbb Z\\ \lfloor y\rfloor - \lfloor x\rfloor&\text{otherwise} \end{cases}$$

Let us look at each of these cases in detail and see why that is so.

If $\lfloor y\rfloor - \lfloor x\rfloor = 0$ that implies that $\lfloor x\rfloor \leq x \leq y = \lfloor x\rfloor + \{y\} < \lfloor x\rfloor + 1$. As there are no integers between $\lfloor x\rfloor$ and $\lfloor x\rfloor + 1$, we get the answer of zero.

Let us look at the third case next, where $\lfloor y\rfloor-\lfloor x\rfloor \neq 0$ and $y\notin\Bbb Z$. We have the following numbers are all integers between $x$ and $y$: $\{\lfloor x\rfloor+1, \lfloor x\rfloor+2,\dots, \lfloor y\rfloor\}$ (note here that $\lfloor x\rfloor\leq x<\lfloor x\rfloor+1\leq\lfloor y\rfloor < y$, so $\lfloor y\rfloor$ is indeed going to be in this list, unlike as is possible in the first and second cases)

The last term in that set can be written instead as $\lfloor y\rfloor = \lfloor x\rfloor +(\lfloor y\rfloor -\lfloor x\rfloor)$. The number of terms in the set is then the same as the number of terms in the set $\{1,2,\dots,\lfloor y\rfloor-\lfloor x\rfloor\}$ which we know to be $\lfloor y\rfloor-\lfloor x\rfloor$.

Finally, looking at the second case, we see it is the same as the third case with the exception that $\lfloor y\rfloor$ will not be included in the list as $x<\lfloor y\rfloor\not < y$, so the list we formed earlier will be correct all but the final term which will be removed, reducing the count by one.

Assuming $x \leq y$

Number of integers = $\max(0, \lceil y \rceil - \lfloor x \rfloor -1)$

In short, push $x$ down to the nearest integer and $y$ up to the nearest integer. The difference between these integers is one more than the number of integers between. The $\max()$ function takes care of the instance where $x = y$ and $x,y \in \mathbb{Z}$, which would result in $-1$.

An integer $n$ between $x$ and $y$ (where $x\le y$) is an integer $n$ with $x<n$ and $n<y$. The former is equivalent to $\lfloor x\rfloor <n$, the latter to $\lceil y\rceil >n$. We infer that the number of integers between two real $x$ and $y$ with $x\le y$ is the same as the number of integers between $\lfloor x\rfloor$ and $\lceil y\rceil$, that is $$\max\{\lceil y\rceil-\lfloor x\rfloor-1,0 \}.$$

Optional part: With $f(x)=ax^2+(a-2)x-2$ we immediately see that $f(0)=-2<0$. Also, $f(-1)=0$. You already noted that $a$ must be positive. Then the condition is met if and only if both $f(1)<0$ and $f(2)\ge 0$. This gives you two simple inequalities in $a$.