When I run this code in ideone with 1 million number primes it works fine but this is generating SIGKILL upon submitting the code.
This is the code that I used to solve the Primes problem8 :
#include <stdio.h>
#include <stdlib.h>
int main(){
int t;
scanf("%i", &t);
if(t > 10)
exit(1);
unsigned long m[t], n[t];
for(int i=0; i<t; i++){
scanf("%li %li", &m[i], &n[i]);
if(m[i] < 1 || n[i] > 1000000000)
exit(1);
if((n[i]-m[i]) > 100000)
exit(1);
}
for(int i=0; i<t; i++){
int prime[n[i]+1];
if(m[i] < 2) m[i] = 2;
for(long j=0; j<=n[i]; j++){
prime[j] = 1;
}
for(long p=2; p*p<=n[i]; p++){
if(prime[p] == 1){
for(long q=p*p; q<=n[i]; q+=p)
prime[q] = 0;
}
}
for(long j=m[i]; j<=n[i]; j++){
if(prime[j] == 1)
printf("%li\n", j);
}
printf("\n");
}
return 0;
}
created
last reply
- 12
replies
- 1.0k
views
- 2
users
- 4
likes
- 4
links