Is there an algorithm to find the most factorizable integer around some specified value?

225 Views Asked by At

Say I have a number (n=337,023) and a maximal distance (d=1,012). Is there an algorithm that would find the number k in the interval between n-d and n+d with the largest number of divisors that is more efficient than simply computing all the factors of all the numbers in the interval?

Added: The question is out of pure curiosity. I had to choose the size of a picture in pixels with some vague constraint (like "width around 700") and was thinking that finding a number that could be divided by a lot of numbers might be more convenient (so that I could partition the image into smaller parts). Then I found myself trying to find nicely divisible numbers around my constraints. I asked quickly google for a way of finding them but without success. (In that particular case an approximate solution was sufficient, or even just a multiple of 12 or 60 or whatever.)

1

There are 1 best solutions below

5
On

For your purpose, I would just store the list of highly composite numbers, OEIS A002182 and find the largest one that divides a number in your range. The example you gave allows numbers from $336,011$ to $338,035$. We can note that $3 \cdot 110,880=332,640$, which is not so far outside your range and has $192$ factors. You could search downward in the list until you find one with a multiple in your range, or you could say that your range is $2024$ so take the largest one less than that so your are guaranteed a multiple and find $201 \cdot 1680 = 337,680$ which has $120$ factors. Just outside your range is $200 \cdot 1680=336,000$ with $128$ factors. This is really an enhancement of choosing a multiple of $60$ and calling it a day, which is not unreasonable.