Skip to the code
cf.
+25 XP

#638 Count Primes in a Range

medium

A math-game leaderboard gives bonus points for prime scores. The designers want to know how many prime scores exist between low and high, both included.

Write countPrimesBetween(low, high) that returns that count.

Example 1

Input: low = 10, high = 20
Output: 4

11, 13, 17, and 19 are the primes from 10 to 20.

Example 2

Input: low = 1, high = 1
Output: 0

1 is not prime.

Constraints

  • 1 <= low <= high <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).