PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000278. Đếm số nguyên tố (Counting Primes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm số nguyên tố (Counting Primes)

Counting Primes

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

For a positive integer NN, let π(N)\pi(N) denote the number of prime numbers not exceeding NN. A prime number is an integer greater than 11 with exactly two distinct positive divisors: 11 and itself.

Compute π(N)\pi(N), the number of primes pp satisfying 2≤p≤N2\le p\le N.

Input

The only line contains a positive integer NN.

Output

Print one non-negative integer equal to the number of primes in [2,N][2,N].

Subtasks

  • Subtask 1 (20 points): 1≤N≤10000001\le N\le 1000000. Time limit: 55 s.
  • Subtask 2 (30 points): 1≤N≤10000000001\le N\le 1000000000. Time limit: 1010 s.
  • Subtask 3 (50 points): 1≤N≤1000000000001\le N\le 100000000000. Time limit: 2020 s.

Examples

Example 1

Input

10

Output

4

Explanation

Among the integers from 22 through 1010, precisely 2,3,5,72,3,5,7 are prime. The remaining values 4,6,8,9,104,6,8,9,10 are composite. Therefore the count is 44.

Example 2

Input

100

Output

25

Explanation

There are 44 primes at most 1010. The intervals 1111–3030, 3131–5050, 5151–7070, and 7171–100100 contain 6,5,4,66,5,4,6 primes respectively, yielding 4+6+5+4+6=254+6+5+4+6=25.

Example 3

Input

100000000000

Output

4118054813

Explanation

For N=1011N=10^{11}, the exact prime-counting value is π(1011)=4 118 054 813\pi(10^{11})=4\,118\,054\,813. Print 4118054813.