View Code of Problem 103

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
#include<cstring>
#include<string>
#include<sstream>
using namespace std;
int a[1000000],b[1000000];
int main() {
	int n1,n2;
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	for(int i=2; i<1000000; i++) {
		if(a[i]==0) {
			for(int j=i+i; j<=1000000; j+=i) {
				a[j]=1;
			}
		}
	}
	for(int i=2; i<1000000; i++) {
		if(a[i]==0)
			b[i]=b[i-1]+1;
		else
			b[i]=b[i-1];
	}
	while(cin>>n1>>n2) {
		cout<<b[n2]-b[n1-1]<<endl;
	}

	return 0;

}

Double click to view unformatted code.


Back to problem 103