# Python 3.x: 66 chars for k in range(2,10**6): if all(k%f for f in range(2,k)):print(k) # More efficient solution: 87 chars Based on the Sieve of Eratosthenes. p=[];z=range(2,10**6) while z:f=z[0];p+=[f];z=[k for k in z if k%f] for k in p:print(k)