文章
13
粉丝
171
获赞
8
访问
45.1k
#include <iostream>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) {
int min, max, sum=0;
if (a > b) {
min = b;
max = a;
} else {
min = a;
max = b;
}
int arr[max+1];
for (int i = 0; i <= max; i++)//初始化一个全为1的数组
arr[i] = 1;
for (int i = 2; i <= max; i++) {//素数的倍数一定不是素数
if (arr[i] == 1) {
for (int j = i; j <= max; j += i) {
arr[j] = 0;
}
arr[i] = 1;
}
}
for (int i = min; i <= max; i++) {
if (arr[i] == 1)
sum++;
}
cout << sum << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发