Interview Question

Senior Software Engineer Interview Pune (India)

Write a program to find prime numbers between 1 to

  100000. primes = [] for x in range(1,100000): for y in range (2, x-1): if x % y == 0: break else: primes.append(x) print "Prime Numbers: ", primes NOW OPTIMIZE IT. (Yeilling)
Answer

Interview Answer

1 Answer

0

THE RANGE OF Y SHOULD BE (2, X/2) INSTEAD OF (2, X-1) FOR OPTIMIZED CODE

Anonymous on Sep 3, 2014

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up