Learn
Exam

Count the Prime Numbers within a Range

Difficulty
STARTER

Problem

Given two natural numbers start and end, write a function solution that returns the count of prime numbers between start and end (inclusive). A prime number is a natural number greater than 1 that has no divisors other than 1 and itself. For example, 2, 3, 5, 7 are prime numbers, but 4, 6, 8 are not.


Constraints

  • start and end are natural numbers between 1 and 100 inclusive.
  • start is less than or equal to end.

Test Case

Test Case Number start end return
1 1 10 4
2 10 20 4
3 5 5 1

Explanation for Test Case 1

  • When start = 1 and end = 10, the prime numbers between 1 and 10 are 2, 3, 5, 7, so the count is 4.

Explanation for Test Case 2

  • When start = 10 and end = 20, the prime numbers between 10 and 20 are 11, 13, 17, 19, so the count is 4.

Explanation for Test Case 3

  • When start = 5 and end = 5, 5 is a prime number, so the count is 1.