FunctionRacerProblemsRace

Twin Primes

MediumMathPython, JavaScript, TypeScript, Java, C++

Twin primes are two primes that differ by exactly 2, like 11 and 13. Return how many twin prime pairs (p, p + 2) exist with both numbers at most n.

Example 1

n 20
returns 4

(3,5), (5,7), (11,13), (17,19).

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems