also what does the number to the right of "running" mean when you have just submitted and its done compiling. It is always running(0). Does that mean something? Does it mean I haven't completed any of the inputs, if that is so something must really be wrong with the program, and probably not the optimization.
Still haven't got it working so are you saying the problem is just that it is not fast enough? Then I have no idea how to improve it without starting over, but the program I have made should be really fast. Also have anyone completed this challenge and knows how they want the output/input?
If SPOJ supported C++11 I would just move primes up to 1000m calculation to the compile time. It probably is still possible in C++03 but is pain in the ass to create. Hmm... You can probably statically initialize first n numbers in your array whare n depends on maximum size of source.
They do care a lot about a line break. The thing with programming competition problems is their output needs to be perfect, meaning even something as stupid as a missing white space or missing line break will give you the incorrect answer.
The computer that is checking your output vs the correct output will see that missing line break as a error and will give you incorrect answer.
Not necessarily. You can still run over the time limit with the wrong output.
The computer doesn't know if you have the exact right output until the end of the program. So once it reaches the designated time limit it just stops checking to see if you have the right answer (Because someone could write a infinite loop and be waiting forever). So it never gets to check to see if its the right answer so it just says the program has hit the time limit.
To demonstrate this, enter this code in the website and submit it for your problem. What answer does it give you?
1 2 3 4 5 6 7 8 9 10 11
int i = 0;
I have done a bunch of SPOJ questions and other websites questions like it. On every one of them you need to have your output formatted perfectly (White spaces and line breaks included).
So for your code you need to come up with a better algorithm to get under the time limit and you need to take care of the formatting like naruku mentioned.
That wasn't really my point. What I meant was exactly what you said, it wouldn't matter because it would say wrong answer if that was the main problem. I am mainly focusing on the algorithm working. I think I have to give this up, I don't want to use too much time on these prime generation algorithms.
The main reasons why is live competitions are checked by humans whereas online are checked by computers which can't pick up on them easy fixes as easily.
But its good practice though, always have the output exactly how it is suppose to be. If you created a program for a customer you wouldn't say well it's no big deal if this text editor doesn't put a space after each word it outputs ;p
I've always wanted to get into live competitions, but never know where to go to sign up for one. It also seems like you need to find a team to enter the competitions and I barely know a few other people that program :(.
@Zereo there have been many single-person teams not associated with any school, ask competition hosts if you can participate. Generally schools and colleges/universities host these competitions, so contact ones in your area.
@Filiprei: Have you tried measuring how long your program takes to execute? It might be close.