I made some changes and this new code of mine got accepted. I tested it for the test case of m=999900000, n=1000000000.
# include < iostream>
# include < cmath>
using namespace std;
void prime(long int a,long int b) {
long int j;
long int k;
int count;
for(j = a; j <= b; j++) {
count = 0;
for(k = 2; k <= sqrt(j); k++) {
if(j%k == 0) {
count++;
}
if(count > 0) {
break;
}
}
if((count == 0)&&(j!=1)) {
cout<<j<<"\n";
}
}
}
int main()
{
int t;
long int n;
long int m;
int i;
cin>>t;
cout<<"\n";
if(t <= 10) {
for(i = 1; i <= t; i++) {
cin>>m;
cout<<" ";
cin>>n;
cout<<"\n";
if((m >= 1)&&(m < 1000000000)&&(n >= m)&&(n <= 1000000000)&&((n-m) <= 100000)) {
prime(m,n);
}
cout<<"\n";
}
}
return 0;
}
Thanks for your suggestions. I really appreciate that. 