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).


$ include "seed7_05.s7i";
  include "bigint.s7i";
 
const func bigInteger: min (in bigInteger: a, in bigInteger: b, in bigInteger: c) is func
  result
    var bigInteger: min is 0_;
  begin
    if a < b then
      min := a;
    else
      min := b;
    end if;
    if c < min then
      min := c;
    end if;
  end func;
 
const func bigInteger: hamming (in integer: n) is func
  result
    var bigInteger: hammingNum is 1_;
  local
    var array bigInteger: hammingNums is 0 times 0_;
    var integer: index is 0;
    var bigInteger: x2 is 2_;
    var bigInteger: x3 is 3_;
    var bigInteger: x5 is 5_;
    var integer: i is 1;
    var integer: j is 1;
    var integer: k is 1;
  begin
    hammingNums := n times 1_;
    for index range 2 to n do
      hammingNum := min(x2, x3, x5);
      hammingNums[index] := hammingNum;
      if x2 = hammingNum then
        incr(i);
        x2 := 2_ * hammingNums[i];
      end if;
      if x3 = hammingNum then
        incr(j);
        x3 := 3_ * hammingNums[j];
      end if;
      if x5 = hammingNum then
        incr(k);
        x5 := 5_ * hammingNums[k];
      end if;
    end for;
  end func;
 
const proc: main is func
  local
    var integer: n is 0;
  begin
    for n range 1 to 20 do
      write(hamming(n) <& " ");
    end for;
    writeln;
    writeln(hamming(1691));
    writeln(hamming(1000000));
  end func;