#include "pch.h"
#include <iostream>
#include <vector>
const int maxn = 1000;
using namespace std;
int pure[maxn];
bool is_pure[maxn];
bool this_is_pure(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return n != 1;
}
int get_pure(int n) {
for (int i = 0; i <= n; i++) {
is_pure[i] = true;
}
is_pure[0] = is_pure[1] = false;
int p = 0;
for (int i = 2; i <= n; i++) {
if (is_pure[i] == true) {
if (this_is_pure(i)) {
pure[p++] = i;
for (int j = i + i; j < n; j = j + i) {
is_pure[j] = false;
}
}
}
}
int a = 0;
return p;
}
int main() {
printf_s("%d", get_pure(11));
}
07-20
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交