Hamming numbers

From Fōrmulæ wiki
Jump to: navigation, search

This page is the answer to the task Hamming numbers in the Rosetta Code.

Description (from Rosetta Code)

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:

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

References

Program

HammingNumbersProgramCode.png

Case 1. First twenty Hamming numbers

HammingNumbersOutput1.png

Case 2. 1691st Hamming number

HammingNumbersOutput2.png

Case 3. One millionth Hamming number

HammingNumbersOutput3.png