I was asked this question in an interview. I implemented an algorithm using sieve of eratosthenes concept and an array.
Is there a better way to go about this question For those who dont know the sieve , here is the link:
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
EDIT: Best in terms of both time and space complexity. I just told them the flaw of SoE is space complexity. So they asked me if I could do something about it . Here is how the interview went about: 1) Implement a algo that prints prime numbers from 1 to n Ans: I implement using SoE 2) Is this the best way to go about it Ans: ???