What's an algorithm to get a number closest to a constant that can evenly (within a margin) divide into two other constants?

Viewed 131

So let't say I have numbers A=1483 and B = 635. My X=100.0

Let's say my allowed MARGIN is 10.0

What's the best way to get the closest number to X (can be floating point) that can divide into A and B with a remainder that is less that MARGIN?

For an answer K. A % K <= MARGIN, B % K <= MARGIN, with K being as close to X as possible, for example |K - X| < 100

2 Answers
Related