7

I'm seeking an efficient implementation of the number-theoretic function giving the smallest integer $n$ that has exactly $k$ factors (not necessarily prime):

```
f[k_Integer]:= ...
```

`f[1] = 1`

because $1$ is the smallest integer that has just a single factor, i.e., $\{ 1 \}$`f[2] = 2`

because $2$ is the smallest integer that has just the two factors, i.e., $\{ 1, 2 \}$`f[3] = 4`

because $4$ is the smallest integer that has exactly three factors, i.e., $\{ 1, 2, 4 \}$`f[4] = 6`

because $6$ is the smallest integer that has exactly four factors, i.e., $\{ 1, 2, 3, 6 \}$`f[5] = 16`

because $16$ is the smallest integer that has exactly five factors, i.e., $\{ 1, 2, 4, 8, 16 \}$`f[6] = 12`

because $12$ is the smallest integer that has exactly six factors, i.e., $\{ 1, 2, 3, 4, 6, 12 \}$`f[7] = 64`

because $64$ is the smallest integer that has exactly seven factors, i.e., $\{ 1, 2, 4, 8, 16, 32, 64 \}$`f[8] = 24`

because $24$ is the smallest integer that has exactly eight factors, i.e., $\{ 1, 2, 3, 4, 6, 8, 12, 24 \}$`f[9] = 36`

because $36$ is the smallest integer that has exactly nine factors, i.e., $\{ 1, 2, 3, 4, 6, 9, 12, 18, 36 \}$

A few moments of thought will show that for $k$ odd, $n$ is a perfect square. Moreover, note that `f[k]`

is not monotonic.

Very inefficient code would advance through increasing $n$ until an integer is found with the criterion of exactly $k$ factors, but this is extremely inefficient for large $k$.

This generates the pairs $n,k$ up to $n=100$:

```
myList = Table[{n, Times @@ (# + 1 & /@ FactorInteger[n][[All, 2]])},
{n, 2, 100}]
```

And it is a simple matter to select cases with a given $k$:

```
Select[myList, #[[2]] == 60]
```

When $k \sim 10^6$, this is somewhat slow and definitely memory intensive.

As background/edification, here is a log plot of $n$ versus $k$.

In 1644, the great mathematician Mersenne asked for `f[60] = 5040`

.

`f[60] = 5040`

`{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 28, 30, 35, 36, 40, 42, 45, 48, 56, 60, 63, 70, 72, 80, 84, 90, 105, 112, 120, 126, 140, 144, 168, 180, 210, 240, 252, 280, 315, 336, 360, 420, 504, 560, 630, 720, 840, 1008, 1260, 1680, 2520, 5040}`

is surprisingly fast. – bbgodfrey – 2018-11-21T03:12:18.990Yes... but I would like to calculate

`f[10^6]`

and even higher, without having to calculate billions of "lower" cases. – David G. Stork – 2018-11-21T03:15:23.297Understand, By the way,

`Table[f[k], {k, 1, 20, 1}]`

is`{1, 2, 4, 6, 16, 12, 64, 24, 36, 48, 1024, 60, 4096, 192, 144, 120, 65536, 180, 262144, 240}`

. Check your`f[4]`

. – bbgodfrey – 2018-11-21T03:20:38.803@bbgodfrey. Oooh... thanks. Fixed. I did the table by hand before I wrote my code. (Bad idea!) – David G. Stork – 2018-11-21T03:23:23.060

The accepted answer fails for ALL extraordinary numbers {8, 16, 24, 32, 48, 64, 72, 80, 96, 108...} and there are infinitely many of them https://oeis.org/A072066. An answer should be accepted only if it returns the correct results.

– J42161217 – 2018-11-21T12:44:48.610https://math.stackexchange.com/a/2733075/416565 – J42161217 – 2018-11-21T14:12:16.417