- 题解
P670 素数个数
- 2023-11-22 16:55:00 @
请高人指点
1 comments
-
Y_ZL LV 8 @ 2023-11-22 20:14:40Edited
欧拉筛
#include <bits/stdc++.h> using namespace std; int p[50010]; int st[50010]; int cnt, n; int main() { cin >> n; memset(st, true, sizeof st); st[1] = false; for (int i = 2; i <= n; i++) { if (st[i]) p[++cnt] = i; for (int j = 1; j <= cnt && i * p[j] <= n; j++) { st[p[j] * i] = false; if (i % p[j] == 0) break; } } cout << cnt; return 0; }
- 1