Bit of an x y problem here, so in full disclosure, I am attempting to find the next term of A152617, "Smallest number m such that m has exactly n distinct prime factors and sigma(m) has exactly n distinct prime factors."
But my main question is, how do you generate all numbers with n distinct prime factors in order? For small n, it's feasible to iterate through the natural numbers and factor each, but for the next term of A152617, getting to even the first number with 13 distinct prime factors (the 13th primorial) in this way is computationally intractable.
Looking at small cases, such as n=4, it seems to be some sort of combinatoric operation of primes and prime powers:
210 = 2 · 3 · 5 · 7
330 = 2 · 3 · 5 · 11
390 = 2 · 3 · 5 · 13
420 = 2^2 · 3 · 5 · 7
462 = 2 · 3 · 7 · 11
510 = 2 · 3 · 5 · 17
546 = 2 · 3 · 7 · 13
570 = 2 · 3 · 5 · 19
630 = 2 · 3^2 · 5 · 7
660 = 2^2 · 3 · 5 · 11
...
Normally, if there was a sporadically growing pattern with two degrees of freedom, to enumerate them in order, I would "batch" all of them in some range, and then sort. But with this problem, the prime powers replace primes, the prime powers can be any size, primes can become arbitrarily large, primes can be missing, so I'm unsure how to even go about choosing an order to enumerate the space due to all the degrees of freedom.
It seems there is an efficient PARI program on A033993 that might encode the algorithm I seek, but I have not yet been able to translate this code into a mental model of an algorithm, and found it more in my current ability to write this question. I've copied the code here for posterity:
(PARI) A246655(lim)=my(v=List(primes([2, lim\=1]))); for(e=2, logint(lim, 2), forprime(p=2, sqrtnint(lim, e), listput(v, p^e))); Set(v)
list(lim, pr=4)=if(pr==1, return(A246655(lim))); my(v=List(), pr1=pr-1, mx=prod(i=1, pr1, prime(i))); forprime(p=prime(pr), lim\mx, my(u=list(lim\p, pr1)); for(i=1, #u, listput(v, p*u[i]))); Set(v) \\ Charles R Greathouse IV, Feb 03 2023
I’d try it like this: Maintain a priority queue that you initialize with the $n$-th primorial, $p_n\#$. In each step, remove the least element from the queue, process it (in this case count the distinct prime factors of its divisor sum) and enter all numbers into the priority queue (if they’re not already there) that you can reach by increasing one of the prime factors to the next prime without changing the number of distinct prime factors. That is, you can increase a prime factor either if it has exponent $1$ and the next prime has exponent $0$ or if it has exponent $\gt1$ and the next prime has exponent $\gt0$. When you process a number of the form $2^kp_n\#$ (including the initial $p_n\#$), also enter $2^{k+1}p_n\#$ into the queue. (These are the smallest numbers with $n+k$ prime factors of which $n$ are distinct.)
I’m not sure exactly how quickly the queue will grow, but I think it should remain manageable up to quite large numbers – it seems plausible that you could reach the next number in that sequence without running out of space.