Practical method for finding a whole number N such that a real number R divided by N is inside a closed interval

23 Views Asked by At

This question came up recently. Let's say we have positive numbers $r,a,b\in\mathbb{R}^+$. What would be the fastest way to find a number $n\in\mathbb{N}$ (considering that $0\notin\mathbb{N}$) such that $\frac{r}{n}\in[a,b]$ (faster than just testing whole numbers until we get the result we want)? By fastest I mean the easiest method to do by hand. Assume $n$ does exist.

If any real $a,b$ is too broad, consider $a=0.28$ and $b=0.3$.

2

There are 2 best solutions below

0
On BEST ANSWER

You want $a \leq r/n \leq b$, or $na \leq r \leq nb$. Then $n \leq r/a$ and $r/b \leq n$. Thus,

$$n \in [r/b, r/a]$$

Calculate the value $m = \operatorname{floor}(r/a)$. Then check if $m > r/b$.

In fact, if you are working in some programming language, you may be able to do

int m = r/a;

and truncation towards zero should help you do it faster.

1
On

This problem does not necessarily have a solution. For example if $r=0.1,$ there is no $ n$ for which $0.28<r/n<0.3$