My computer runs the worst case scenario (or close: 999999990 - 1000000000) slowly but fine. I haven't been getting any errors from the code submitted (segmentation faults or otherwise). I've been staring at the code for a while, but I am really at a loss without being able to recreate the error. Anyone see anything I'm missing? Thanks in advance.
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int cases;
string input;
cin>>input;
cases = atoi(input.c_str());
for( int i = 0; i < cases; i++){
long numbers[100000];
int splitAt;
long min, max;
do{
getline(cin, input, '\n');
//cout<<input;
} while(input=="");
splitAt = input.find(" ", 0);
min = atol( input.substr(0,splitAt).c_str() );
max = atol( input.substr(splitAt+1, input.length() - splitAt).c_str() );
for( long j = 0; j<=max-min; j++ ){
numbers[j] = j+min;
//cout<<j<<": "<<numbers[j]<<endl;
}
for( long j = 2; j <= sqrt(max); j++ ){
long startPos = 0;
while(( numbers[startPos]%j != 0 )||(numbers[startPos]==0)){
startPos++;
}
//cout<<"For "<<j<<" start at "<<numbers[startPos]<<". Get rid of: "<<endl;
for( long k = startPos; k <= max-min; k+=j ) {
if(( numbers[k] != j )&&(numbers[k]!=0)){
//cout<<k<<":"<< numbers[k]<< ", ";
numbers[k] = 0;
}
}
//cout<<endl;
}
for( long j = 0; j <= max-min; j++ ){
if( numbers[j] != 0 )
cout<<numbers[j]<<endl;
}
}
return 0;
}