Primes... again
Given two integers N and M (N ≤ M), output all the prime numbers between N and M inclusive, one per line.N and M will be positive integers less than or equal to 1,000,000,000.
The difference between N and M will be less than or equal to 5,000,000.
Sample Input
5 20
Sample Output
5 7 11 13 17 19
All Submissions
Best Solutions
Point Value: 15 (partial)
Time Limit: 5.00s
Memory Limit: 32M
Added: Oct 18, 2008
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
If you're adamant about trying this (good on you! determination is important), I wrote a hint comment a while ago.
Does this mean that I timed out? What does it mean?
(It would be helpful if I could see the error message)
In other languages, any solution that times out with 2 seconds will still time out with 5 seconds.
In my opinion, if you're not using a language that uses almost every machine instruction doing calculations (C, C++, Pascal, assembly) then you're already doing something wrong.
As Daniel said, with the right idea, output optimisation is unnecessary and over-complicates your code.
Here's a hint: If you know all the primes up to some number M, you can determine all the primes up to some number N. How are M and N related? (Yes, your code implies you already know this; you're just not applying it in the best way.)
Is it, a), an integer,
b) string,
c) char?
An array as well, right?