Problems > Count the Primes

Count the Primes

Difficulty: 1300 3000 ms 128 MB

math number-theory

How many primes are there in the range [1, N]?

Input: one integer N.

Output: the number of primes ≤ N.

Constraints:

  • 1 ≤ N ≤ 106

Sample Tests

Input 1
10
Output 1
4
Input 2
1
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.