n-smooth   numbers are positive integers which have no prime factors  >  n.

The   n   (when using it in the expression)   n-smooth   is always prime,

there are   no   9-smooth numbers.

1   (unity)   is always included in n-smooth numbers.




2-smooth   numbers are non-negative powers of two.

5-smooth   numbers are also called   Hamming numbers.

7-smooth   numbers are also called    humble   numbers.



A way to express   11-smooth   numbers is:

  11-smooth  =  2i × 3j × 5k × 7m × 11p

           where     i, j, k, m, p ≥ 0  



Task

   calculate and show the first   25   n-smooth numbers   for   n=2   ───►   n=29
   calculate and show   three numbers starting with   3,000   n-smooth numbers   for   n=3   ───►   n=29
   calculate and show twenty numbers starting with  30,000   n-smooth numbers   for   n=503   ───►   n=521   (optional)


All ranges   (for   n)   are to be inclusive, and only prime numbers are to be used.

The (optional) n-smooth numbers for the third range are:   503,   509,   and   521.

Show all n-smooth numbers for any particular   n   in a horizontal list.

Show all output here on this page.



Related tasks

   Hamming numbers
   humble numbers


References

   Wikipedia entry:   Hamming numbers     (this link is re-directed to   Regular number).
   Wikipedia entry:   Smooth number
   OEIS entry:   A000079    2-smooth numbers or non-negative powers of two
   OEIS entry:   A003586    3-smooth numbers
   OEIS entry:   A051037    5-smooth numbers or Hamming numbers
   OEIS entry:   A002473    7-smooth numbers or humble numbers
   OEIS entry:   A051038   11-smooth numbers
   OEIS entry:   A080197   13-smooth numbers
   OEIS entry:   A080681   17-smooth numbers
   OEIS entry:   A080682   19-smooth numbers
   OEIS entry:   A080683   23-smooth numbers


with javascript_semantics 
include mpfr.e
 
function nsmooth(integer n, integer needed)
-- note that n is a prime index, ie 1,2,3,4... for 2,3,5,7...
    sequence smooth = {mpz_init(1)},
             nexts = get_primes(-n),
             indices = repeat(1,n)
    for i=1 to n do nexts[i] = mpz_init(nexts[i]) end for
    for i=2 to needed do
        mpz x = mpz_init_set(mpz_min(nexts))
        smooth = append(smooth,x)
        for j=1 to n do
            if mpz_cmp(nexts[j],x)<=0 then
                indices[j] += 1
                mpz_mul_si(nexts[j],smooth[indices[j]],get_prime(j))
            end if
        end for
    end for
    return smooth
end function
 
function flat_str(sequence s)
    for i=1 to length(s) do s[i] = shorten(mpz_get_str(s[i]),ml:=10) end for
    return join(s," ")
end function
 
for n=1 to 10 do
    printf(1,"%d-smooth[1..25]: %s\n",{get_prime(n),flat_str(nsmooth(n, 25))})
end for
for n=1 to 10 do
    printf(1,"%d-smooth[3000..3002]: %s\n",{get_prime(n),flat_str(nsmooth(n, 3002)[3000..3002])})
end for
for n=96 to 98 do   -- primes 503, 509, and 521
    printf(1,"%d-smooth[30000..30019]: %s\n",{get_prime(n),flat_str(nsmooth(n, 30019)[30000..30019])})
end for
