PRIMES2 - Printing some primes (Hard)
The problem statement is really simple (the constraints maybe not). You are to write all primes less than 10^9.
There is not input.
To make the problem less output related write out only the 1st, 501st, 1001st, ... 1st mod 500.
Input: Output: 2 3581 7927 ... 999978527 999988747 999999151
Can any one tell me how to optimize Output in Java to get under Time Limit. am already using PrintWriter class for output
Would someone be kind enough to tell me which topics should I learn to avoid Tle ??
@Howard Roark: you need to output every 500th prime number, about 100,000 total
This will be a real challenge on Java. All the optimizations will be needed just to get to computation of the list of primes to come in under the time limit, and that's not even counting the time needed for the I/O. The I/O will also require optimizations to reduce the cost of converting all those integers (about 50 million) to base 10 strings.
VISHAL DEEPAK AWATHARE:
in hints on to get the crazy speed?
My code is spending all the time trying to output the numbers, if I just comment out the printf statements, It is taking a little over 3s to run, but with the io it is going to about 14s, is there a faster way to print?