文章
43
粉丝
180
获赞
21
访问
196.1k
#include <iostream>
using namespace std;
const int N = 1e7 + 10;
int a, b, cnt;
int primes[N];
bool st[N];
int get_primes(int x)
{
for (int i = 2; i <= x; i ++ )
{
if (!st[i]) primes[cnt ++] = i;
for (int j = 0; primes[j] <= x / i; j ++ )
{
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
int main()
{
get_primes(N);
while (cin >> a >> b)
{
int res = 0;
for (int i = a; i <= b; i ++ ) if (st[i]) res ++;
cout << res << endl;
}
return 0;
}
登录后发布评论
厦大好像要求要用c语言,呜呜呜呜呜呜呜