find smallest number $M$ for which the remainder of $N/M$ is equal to $3$

57 Views Asked by At

given a positive integer $N$ greater than $3$, is there a smart or algorithmic way to find the smallest number $M$ for which the remainder of $N/M$ equals $3$? one obvious answer is always $N-3$, but this is rarely the smallest one.

1

There are 1 best solutions below

2
On BEST ANSWER

The desired $M$ is the smallest divisor of $N-3$ that is greater than $3$. If you have the prime factorization of $N-3$, this is easy to find; if not, I don't know an efficient procedure. (There is of course a simple procedure: just test possible divisors starting with $4$.)