import java.util.Scanner;
public class Main {
public static int[] primes = new int[10000010];//用来存储所有的素数
//用来记录第i个数是不是素数,如果是素数st[i] = false,如果不是素数st[i] = ture
//boolean的默认值为false
//故初始情况下,默认所有数都是素数,都是false,当筛到不是素数的数时,将st[i]置为ture
public static boolean[] st = new boolean[10000010];
public static int count;//用来统计素数的数目
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
get_primes(n);
}
//普通筛法 O(nlogn)
//即从前往后,把每一个数的倍数筛掉
public static void get_primes(int n) {
for (int i = 2; i <= n; i++) {
//如果是质数
if (st[i] == false){
primes[count++] = i;
}
//不管当前i是合数还是质数,都用来筛掉后面它的倍数
//st[j]从2*i,到3*i,一直到n,全部置为ture
for (int j = i + i; j <= n; j += i) {
st[j] = true;
}
}
System.out.println(count);
}
}
import java.util.Scanner;
public class Main {
public static int[] primes = new int[10000010];//用来存储所有的素数
//用来记录第i个数是不是素数,如果是素数st[i] = false,如果不是素数st[i] = ture
//boolean的默认值为false
//故初始情况下,默认所有数都是素数,都是false,当筛到不是素数的数时,将st[i]置为ture
public static boolean[] st = new boolean[10000010];
public static int count;//用来统计素数的数目
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
get_primes(n);
}
//埃式筛的时间复杂度为 O(nloglogn)
//即从前往后,把质数的倍数筛掉
public static void get_primes(int n) {
for (int i = 2; i <= n; i++) {
//如果是质数
if (st[i] == false){
primes[count++] = i;
//在质数的基础上,筛掉质数的倍数
for (int j = i + i; j <= n; j += i) {//st[j]从2*i,到3*i,一直到n,全部置为ture
st[j] = true;
}
}
}
System.out.println(count);
}
}