线性筛
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
//#include <tr1/unordered_map>
//#include <bits/stdc++.h>
#include <cmath>
//#include <unordered_map>
using namespace std;
#define sfd(i) scanf("%d", &i)
#define sfl(i) scanf("%I64d", &i)
#define sfs(i) scanf("%s", (i))
#define prd(i) printf("%d\n", i)
#define prl(i) printf("%I64d\n", i)
#define sff(i) scanf("%lf", &i)
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define mst(x, y) memset(x, y, sizeof(x))
#define INF 0x3f3f3f3f
#define inf 8e19
#define eps 1e-10
// const int maxn = 3e5;
#define PI acos(-1.0)
#define lowbit(x) ((x) & (-x))
#define fl() printf("flag\n")
#define MOD(x) ((x % mod) + mod) % mod
#define endl '\n'
#define pb push_back
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0)
//-----------------------------------------------
const int N = 1e6 + 10;
bool st[N];
int primes[N], cnt;
//素数打表
void get_primes(int n)
{
for(int i = 2; i <= n; i++)
{
if(!st[i]) primes[cnt ++] = i;
for(int j = 0; primes[j] <= n / i; j ++)
{
st[primes[j] * i] = true;
if(i % primes[j] == 0) break;
}
}
}
int main()
{
int n;
cin >> n;
get_primes(n);
cout << cnt << endl;
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/10720.html