A natural number greater than zero is a Hamming number if its divisors are only 2, 3 or 5. The twelve first Hamming numbers are 1, 2, 3, 4, 5, 8, 9, 10, 12, 15 and 16. However, neither 42 nor 97 are not Hamming numbers: 42 is divisible by 7, and 97 is a prime number greater than 5.
Your task is to write a program that prints the first Hamming numbers for different values of .
Your program must include and use the function
bool is_hamming(int x);
that indicates if a natural number |x| greater than zero is a Hamming number or is not.
The input is a sequence of natural numbers.
For each natural number of the input print, in a line and separated by commas, the first Hamming numbers in increasing order.
There are astute ways to generate the first Hamming numbers sorted. We do not ask you to discover them: simply, implement a reasonable algorithm.
Input
12 2 6 0 1
Output
1,2,3,4,5,6,8,9,10,12,15,16 1,2 1,2,3,4,5,6 1