View Code of Problem 103

#include<iostream>
#include<vector>
using namespace std;
int main() {
	int a,b;
	vector<bool> v(1000001,1);
	v[1]=0;
	//埃拉托色尼筛选算法 
	for(int i=2; i<=1000000; i++) {
		if(v[i]) {
			for(int j=i*2; j<=1000000; j+=i) v[j]=0;
		}
	}
	while(cin>>a>>b) {
		//[a,b] 
		int count=0;
		for(int i=a; i<=b; i++) {
			if(v[i]) count++;
		}
		cout<<count<<endl;
	}
}

Double click to view unformatted code.


Back to problem 103