Here is the code below (ans to a CP qs)
The time limit for execution is 6 seconds but my code is slower than.
How can I make it more memory and time efficient ?
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.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
long int t,m,n,i,j,k;
//printf("Enter number of testcases:\n");
scanf("%ld",&t);
long int test[t][2];
for(i=0;i<t;i++){
//printf("Enter m,n:\n");
scanf("%ld %ld",&test[i][0],&test[i][1]);
}
for(k=0;k<t;k++){
for(i=test[k][0];i<=test[k][1];i++){
for(j=2;j*j<i*i;j++){
if(i%j==0)
break;
}
if(j==i){
printf("%ld\n",i);
}
}
printf("\n");
}
return 0;
}