Hamming numbers are numbers of the form  

    H = 2i × 3j × 5k
           where 
     i,  j,  k  ≥  0 

Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5).



Task

Generate the sequence of Hamming numbers, in increasing order.   In particular:

 Show the   first twenty   Hamming numbers.
 Show the   1691st   Hamming number (the last one below   231).
 Show the   one millionth   Hamming number (if the language – or a convenient library – supports arbitrary-precision integers).


Related tasks

 Humble numbers
 N-smooth numbers


References

 Wikipedia entry:   Hamming numbers     (this link is re-directed to   Regular number).
 Wikipedia entry:   Smooth number
 OEIS entry:   A051037   5-smooth   or   Hamming numbers
 Hamming problem from Dr. Dobb's CodeTalk (dead link as of Sep 2011; parts of the thread here and here).


#X2 = 2
#X3 = 3
#X5 = 5
 
Macro Ham(w)
  PrintN("H("+Str(w)+") = "+Str(Hamming(w)))
EndMacro
 
Procedure.i Hamming(l.i)
  Define.i i,j,k,n,m,x=#X2,y=#X3,z=#X5
  Dim h.i(l) : h(0)=1
  For n=1 To l-1
    m=x
    If m>y : m=y : EndIf
    If m>z : m=z : EndIf
    h(n)=m
    If m=x : i+1 : x=#X2*h(i) : EndIf
    If m=y : j+1 : y=#X3*h(j) : EndIf
    If m=z : k+1 : z=#X5*h(k) : EndIf    
  Next
  ProcedureReturn h(l-1)
EndProcedure
 
OpenConsole("Hamming numbers")
For h.i=1 To 20
  Ham(h)  
Next
Ham(1691)
Input()