Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count Primes

XPChallenge Points: 20
levelLevel: Medium

Given an integer n, return the number of prime numbers that are strictly less than n.
A prime number is a number greater than 1 that is divisible only by 1 and itself.
Your task is to count all such prime numbers that are smaller than the given number n.

Example 1:

Input: n = 5

Output: 6

Explanation:

Prime numbers less than 5 are [2, 3].

Example 2:

Input: n = 20

Output: 8

Explanation:

Prime numbers less than 20 are [2, 3, 5, 7, 11, 13, 17, 19]. Hence, the count is 8.

Example 3:

Input: n = 15

Output: 2

Explanation:

Prime numbers less than 15 are [2, 3, 5, 7, 11, 13].

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result