How to get smooth numbers efficiently by using dependent iterators in Table

I have the following code for getting smooth numbers up to Prime[4] :

g = 100;

t1 = Table[{2^x*3^y*5^z*7^u}, {u, 0, Log[7, g]}, {z, 0, Log[5, g/(7^u)]}, {y, 0, Log[3,g/(7^u*5^z)]}, {x, 0, Log[2, g/(7^u*5^z*3^y)]}]
t2 = Sort[Flatten[t1]]


I am looking for a general solution for k Primenumbers (in ascending order) using Table which refers to iterators appearing in the loop before. I know I can use FactorInteger and Select or fast code from (Creating a Table with varying depth and interdependent limits) to solve this problem, but how to tackle it using Table? Is there a way to do this? I think the answer lies somewhere in Table with dependent iterator but here are too many tiwsts for my level of understanding.

• This is somehow relevant demonstrations.wolfram.com/ConsecutiveSmoothNumbers Commented Aug 26, 2020 at 18:12
• If you look at the sequence A002473, there are several codes for mathematica. Commented Aug 26, 2020 at 18:15
• Interesting link! Thanks! Commented Aug 28, 2020 at 12:22

Clear["Global*"]

g = 100;

t1 = Table[{2^x*3^y*5^z*7^u}, {u, 0, Log[7, g]}, {z, 0, Log[5, g/(7^u)]}, {y,
0, Log[3, g/(7^u*5^z)]}, {x, 0, Log[2, g/(7^u*5^z*3^y)]}];

t2 = Sort[Flatten[t1]]

(* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, \
30, 32, 35, 36, 40, 42, 45, 48, 49, 50, 54, 56, 60, 63, 64, 70, 72, 75, 80, \
81, 84, 90, 96, 98, 100} *)


Generalizing to n primes

smooth[n_Integer?Positive, g_Integer?Positive] :=
Module[{a, func, factors, iterators,
primes = Prime /@ Range[n],
vars = Array[a, n]},
func = Times @@ (primes^vars);
factors = #[[1]]^#[[2]] & /@ Transpose[{primes, vars}];
iterators = {#[[1]], 0, Log[#[[2]], #[[3]]]} & /@
Transpose[{
Reverse@vars,
Reverse@primes,
g/FoldList[Times, 1, Most@Reverse@factors]}];
Table[func, Evaluate[Sequence @@ iterators]] // Flatten // Sort // Quiet]


Checking against original calculations

smooth[4, g] == t2

(* True *)

• Wow! You put all the puzzle parts together. Like a piece of art! Great! The only part I still have to struggle with is Evaluate Sequence. I read the manual but it is still not very clear to me. Commented Aug 27, 2020 at 10:13
• Table requires a sequence of one or more iterators. iterators is a list of the iterators. Sequence @@ iterators would convert the list into a sequence. However, since Table has the attribute HoldAll, the conversion would not be done when it needs to be. Evaluate forces early evaluation of this conversion so that Table` sees the required sequence. Commented Aug 27, 2020 at 14:46
• Thank you for clearing things up! Commented Aug 27, 2020 at 15:39