Skip to the code
cf.
+25 XP

#639 Split Into Two Prime Groups

medium

A load-testing tool splits n virtual users into two groups, and for its hashing scheme both group sizes must be prime numbers. n is even and at least 4.

Write primeSplit(n) that returns [p, q] with p and q prime, p <= q, and p + q === n. If several pairs work, return the one with the smallest p. (Every even n from 4 up to the constraint has such a pair.)

Example 1

Input: n = 10
Output: [3,7]

3 + 7 = 10 and 5 + 5 = 10 both work. 3 is the smaller first part.

Example 2

Input: n = 4
Output: [2,2]

2 + 2 is the only split.

Constraints

  • 4 <= n <= 10^6
  • n is even.
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).