Find the nearest value in multiplication table

179 Views Asked by At

Let's say I have multiplication table 20 a = 20

A point on grid let say say 517 b = 517

Now I need a formula to find nearest number on both sides of this point on multiplication table. The answer will be 500 and 520. What could be the formula to get these both numbers using a and b

Or in other words closest multiples of 20 on either side of 517?

2

There are 2 best solutions below

1
On BEST ANSWER

In your example, the reason we get the answer to be $500$ and $520$ is because $$\lfloor517\div20\rfloor=25\quad\text{and}\quad20\times25=500\quad\text{and}\quad20\times26=520.$$

As such, in general, we have the two answers as needed as $$a\left\lfloor\frac{b}{a}\right\rfloor\quad\text{and}\quad a\left(\left\lfloor\frac{b}{a}\right\rfloor+1\right).$$

2
On

I believe you are looking for the two numbers $$a\left\lfloor\frac{b}{a}\right\rfloor,\quad a\left\lceil\frac{b}{a}\right\rceil$$ using the floor and ceiling functions respectively.