@Peilonrayz hit the point by mentioning the real problem with your your your implementation design which is the algorithm complexity. So I want to go further: AFAIK, the fastest known algorithm that prime numbers generator isalgorithm is Sieve of Atkin. YouSo you should consider this algorithm as a starting point for an effective solution for the sake of algorithm complexity.