#include<iostream> #include<algorithm> #include<cmath> using namespace std; const int MAX=1000001; bool h[MAX]={0}; void f(){ for(int i=2;i<MAX;i++){ if(h[i]==false) { for(int j=i+i;j<MAX;j+=i){ h[j]=true; } } } } int main(){ long long a,b; f(); h[0]=true; h[1]=true; while(~scanf("%d %d",&a,&b)){ int cnt=0; for(int i=a;i<=b;i++) if(h[i]==false) cnt++; printf("%d\n",cnt); } } |
Double click to view unformatted code.