# Find the next divisor without remainder

I divide a value and if the remainder is not 0 I want the closest possible divisor without remainder.

Example:

I have:
$100 \% 48 = 4$

Now I am looking for the next value which divide 100 wihtout remainder. Result: $50$
$100 \% 50 = 0%$

Just another example:
$14 \% 6 = 2$
Result $7$
$14 \% 7 = 0$

Does anyone know how to calculate this?

-
It seems that you know how to calculate this. Are you looking for some other way to calculate it? – vadim123 Mar 17 '14 at 15:20
No, I don´t know. My "results" are just guessed. – Viatorus Mar 17 '14 at 15:22
If there were an easy way of doing this in general we'd be able to factorise large numbers using the method. And no-one knows an easy way to do that. – Mark Bennet Mar 17 '14 at 16:12

1. Calculate 100%48. If the answer is zero, stop. Otherwise:
2. Calculate 100%49. If the answer is zero, stop. Otherwise:
3. Calculate 100%50. If the answer is zero, stop. Otherwise:

etc.

-
doing so you'll find an integer $x \text{ such that } x \equiv 0 \text{ mod } M$, but not the nearest...e.g maybe it was $47$ – sirfoga Mar 17 '14 at 15:26
Okay, well I hoped there is a better way to calculate this. But thank you anyway. – Viatorus Mar 17 '14 at 15:26
If you want the nearest and allow those less than 48, then try: 48, 49, 47, 50, 46, 51, 45, etc. – vadim123 Mar 17 '14 at 15:29

I know this is old, but I was looking for an answer to the same question and I think I figured it out. Perform your initial division (e.g. 100/48=2.08333...), round the quotient to the nearest integer (2.08333... -> 2), divide that into the original number, and that gives you the closest divisor that evenly divides into the dividend (100/2=50). Or for your second example, 14/6=2.333..., 2.333->2, 14/2=7. This won't always give you an integer divisor, however.

-