View Code of Problem 103

#include <bits/stdc++.h>
using namespace std;
long int issushu(long int n )
{
	if(n<=1)
		return 1;
	int sqr=(int)sqrt(1.0*n);
	for(int i=2;i*i<=n;i++)
		if(n%i==0)
			return 0;
	return 1;
}
int main() 
{	
	long int n,i,a,b;
	bool hashtable[1000010]={false};
	for(i=0;i<1000010;i++)
	{
		if(issushu(i))
			hashtable[i]=true;
	}
	while(cin>>a>>b)
	{
		long int k=0;
		for(i=a;i<=b;i++)
		{
			if(hashtable[i]==true)
				k++;
		}
		cout<<k<<endl;
	}
}

Double click to view unformatted code.


Back to problem 103