hey, is there an optimized way to generate primes between 2 limits ?

I was recently asked this question in an interview.

Obviously, the Brute Force method would be to run a loop between the limits and check if each number has a factot between 2 and square-root of the number.

Thats probably O(n2) + O(n) == O(n2) .

Is there an opimized way ???