Please help me with the following question. There are three prime numbers given $p_1, p_2$ and $p_3$. Print the first $k$ numbers with only these prime numbers as factors.
Expected solution complexity: $O(k)$
For example: the three prime numbers are $2, 3, 7$.
First $7$ numbers with these as factors are $2, 3, 4, 6, 7, 8, 9$.
Without loss of generalization we can assume $p_1 < p_2 < p_3$
OK, the first one is obvious: $p_1$
For the second one, pick the smallest one of $p_1^2$ and $p_2$
If that was $p_1^2$, then for the third one pick the smallest one of $p_1^3$, $p_2$
If the second was $p_2$, then for the third one pick the smallest one of $p_1^2$ and $p_3$.
For ones after that, see other Answers!