1 / 4
Jun 2015

when i ran my program in ideone.com it was running within the time limit. But here it says 'time limit exceeded'?? exclamation plzz help...

#include<iostream>
int main()
{
	int t,m,n;
	std::cin>>t;
	while(t--)
	{
		std::cin>>m>>n;
		for(int i=m;i<=n;i++)
		{
			int f=0;
			for(int j=1;j<=i;j++)
			if(i%j==0)
			f++;
			if(f==2)
			std::cout<<i<<"\n";
		}
		std::cout<<'\n';
	};
	return 0;
}
  • created

    Jun '15
  • last reply

    Jun '15
  • 3

    replies

  • 827

    views

  • 2

    users

I cannot be able to minimise the time limit. Should i use array for this? If yes then how should i do it?

You need to think about how much information you need to be certain tgat a number n is prime.