This is my simple (IT IS!) code for generating primes. I made it to search from 1 to the sqrt of the no. being tested. I certainly do not know any other way to optimise it(believe me). Plus on my computer and ideone it runs wid no problems. PLEASE HELP! HOW TO AVOID TLE!?
#include<stdio.h>
#include<math.h>
int main()
{
int s,t,m,n,j,flag,i;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
i = m;
s = sqrt(i);
while(i<=n)
{
flag=0;
for(j=1;j<=s;j++)
{
if(i%j==0)
flag++;
}
if((flag==2)&&i<=n)
printf("%d\n",i);
i++;
}printf("\n");
}
}