Closest divisor

3.8k Views Asked by At

Given two whole numbers, $N$ and $m$, a third whole number $c$ is the one that holds $N\bmod c= 0$ and has the minimal $|c-m|$.

In other words, $c$ is a divisor of $N$ closest to $m$.

Examples (in the form of $f(N, m) = c$):

$f(10, 2) = 2$

$f(13, 10) = 13$

$f(25, 7) = 5$

$f(60, 10) = 10$

I'm trying to figure out an efficient algorithm to find $c$, but I can't find a similar problem to relate to it. I'm not sure if I'm not using the right keywords.

What is the best way to do that?

1

There are 1 best solutions below

0
On BEST ANSWER

If we could find out the closest divisor efficiently, choosing the second number as the rounded square root of the given number would either give us a non-trivial factor or it would show that the given number is prime which makes the problem trivial.

Hence, finding the closest divisor must at least be as hard as integer factoring. But we do not know an efficient method for integer factoring, so there will not be an efficient method to find the closest divisor either.