文章
33
粉丝
78
获赞
3
访问
18.4k
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1000000 + 5;
int prime[maxn];
void getprime() {
memset(prime, 0, sizeof(prime));
for (int i = 2; i <= maxn; i++) {
if (!prime[i]) prime[++prime[0]] = i;
for (int j = 1; j <= prime[0] && prime[j] * i <= maxn; j++) {
prime[prime[j] * i] = 1;
if (i % prime[j] == 0) break;
}
}
}
int main(){
getprime();
int a,b;
while(cin >> a >>b){
if(a > b) swap(a,b);
int count = 0;
for(int i = 1;i < maxn;i++){
if(prime[i] >=a) count++;
if(prime[i] >b) {
count--;
break;
}
}
cout <<count<<endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发