#include <cstdio>
#include <cstring>
#include <cmath>
bool isp[5000000 + 5];
int main()
{
int l, r;
scanf("%d %d", &l, &r);
int m = sqrt(r + 0.5);
memset(isp, true, sizeof(isp));
isp[0] = isp[1] = false;
for (int i = 2; i <= m; i++)
{
if (isp[i] == true)
{
for (int j = i * i; j <= r; j += i)
{
isp[j] = false;
}
}
}
int cnt = 0;
for (int i = l; i <= r; i++)
{
if (isp[i] == true)
{
cnt++;
}
}
printf("%d\n", cnt);
}
【codevs1453 统计素数个数2】E氏筛法
最新推荐文章于 2020-10-08 10:08:26 发布