SPOJ problem PRIME1 (also found on other sites in identical form):
Input
The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output
For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.
My Answer:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int iter = 0;
scanf("%d",&iter);
while(iter--) {
long num1, num2;
scanf("%ld%ld",&num1,&num2);
long prime[60000];
prime[0] = 2;
long prime_count = 1;
long result[60000];
long result_count = 0;
if(num1 <= 2){
result[0] = 2;
result_count++;
printf("2\n");
}
for(long i = 3; i <= num2; i++) {
int isPrime = 1;
for(long j = 0; j < prime_count; j++) {
if(i % prime[j] == 0) {
isPrime = 0;
break;
}
}
if(isPrime) {
prime[prime_count] = i;
prime_count++;
if(i >= num1){
result[result_count] = i;
result_count++;
printf("%ld\n",i);
}
}
}
printf("\n");
}
return 0;
}
Is there any way to improve my code?