fork(4) download
  1. primesLeft = 999 #1000 primes to find, excluding 2 (only even)
  2. trialNum = 3 #not counting 1, 3 is our second of 1000
  3. while primesLeft>0: #until we find our 1000th prime
  4. for divisorNum in range (2, trialNum/2):#divide by all #s btwn 1 and half of trialNum
  5. if (trialNum % divisorNum) == 0: #if trial/divisor has no rem (divides perfectly)
  6. print trialNum,"is not prime", divisorNum, "is a factor"
  7. trialNum = trialNum+2
  8. else: #if trial/divisor has rem
  9. primesLeft = primesLeft - 1
  10. print trialNum,"is prime. primesLeft ==", primesLeft
  11. trialNum = trialNum + 2
  12. print "1000th prime is ",trialNum-2
Time limit exceeded #stdin #stdout 5s 7732KB
stdin
Standard input is empty
stdout
Standard output is empty