Hey guys I'm doing this problem on SPOJ and basically when provided a beginning and end integer limit m and n respectively, it outputs all the prime in that range.
#include <iostream>
usingnamespace std;
int main() {
// your code goes here
int numberOfLines;
int m; //beginning of prime numbers
int n; //ending of prime numbers
int x;
int *arrayPtr;
//Read in the numbers
std::cin >> numberOfLines;
//Loop and create/delete array per line
for (int i = 0; i < numberOfLines; i++){
std::cin >> m >> n;
arrayPtr = newint[(n-m)+1];
int counter = 0;
//Check condition m >= 1 && n >=1
if (m >= 1 && n >= 1)
//check second condition
if ( m <= 1000000000 && n <= 1000000000)
//check third condition
if (n-m<= 100000){
for (int x = m; x <= n; x++){
if (x == 1){ //do nothing if 1
}
elseif (x == 2 || x == 3 || x == 5 || x == 7 || x == 11){
arrayPtr[counter] = x;
counter++;
}
elseif (x%2 == 0 || x%3 == 0 || x%5 == 0 || x%7 == 0 || x%11 == 0)
{}
else
{
arrayPtr[counter] = x;
counter++;
}
}
}
for (int i = 0; i < counter; i++)
std::cout << arrayPtr[i] << "\n";
std::cout << "\n";
delete arrayPtr;
}
return 0;
}
When I input my test cases I get all the primes that are possible within that range: http://ideone.com/wfgutK
I can't tell why but the SPOJ system keeps evaluating my answer as wrong.
:(
169 (13^2) is a composite number indivisible by 2, 3, 5, 7, or 11.
17^2 is also a composite number, as is 19^2.
In fact, there exists no finite list of primes sufficient to find all primes and no composites.