Prime generator

time limit exceeded

You can optimize the code using Sieve of Eratosthenes.