How to find the smallest number exceeding $n$ with at least $m$ prime factors

178 Views Asked by At

I'm wondering if there is a clever way to find the next number containing at least $m$ prime factors (not necessarily distinct) after a given number $n = p_1 \dots p_{m+k}$ given with prime factors.

Example: ($m := 2$) $$ n_0 = 2 \cdot 2 = 4 \\ n_1 = 2 \cdot 3 = 6 \\ n_3 = 2 \cdot 2 \cdot 2 = 8 \\ n_4 = 3 \cdot 3 = 9 \\ n_5 = 2 \cdot 5 = 10 $$

This is relatively easy, since for $m = 2$ only the prime numbers will be missing in this series. But how would I proceed if I was given $m$ and a number $n = p_1 \cdot ... \cdot p_{m+k}$ ($k \in \mathbb{N_o}, \;\;p_1, ... p_{m+k}$ primes in ascending order)?

How could I find the smallest number greater $n$ with at least $m$ prime factors?