time limit exceeded in spoj prime generator... what can i do???

#include<stdio.h>
int main()
{
int i,j,t,a,b,k,c,f;
printf(“ENTER THE NO OF TEST CASES\n”);
scanf("%d",&t);
if(t>10)
exit(0);
int arr[2t];
printf("\nENTER THE RANGE FOR %d CASES\n",t);
for(i=0;i<(2
t);i++)
{
scanf("%d",&arr[i]);
}
i=0;
for(j=1;j<=t;j++)
{
a=arr[i];
b=arr[i+1];
for(c=a;c<=b;c++)
{
int k=2;
while(k<c)
{
f=c%k;
if(f==0)
{
break;
}
k++;
}
if(k==c&&f!=0||c==2)
printf("\n%d",c);

 }
 printf("\n");
 i+=2;

}
return 0;
}

@shashank13_ the constraints for this problem are very large… brute force will result in TLE.

You have to use the concept of sieve for this. Read this and this.

Also remove these printf statements:

  1. “ENTER THE NO OF TEST CASES\n”,

  2. “ENTER THE RANGE FOR %d CASES\n”

these will result in WA.

You are getting TLE as the constraints are very large.
You can see **Primality test, sieve of Eratosthenes, or Rabin Miller test.
Also obey the above comment by @rjohari23 to avoid wrong answer.

links :

You are getting TLE because of the constraints. Applying brute force will give you a TLE.
go through this
and this