TypeScriptEasyMath10 min

Test whether a number is prime

Return whether the integer is prime; values below 2 are not prime. Inputs are valid JSON and must not be modified unless the algorithm uses a local copy. This exercise probes typed data modeling, boundary handling, and algorithm selection.

Input

One JSON value: number. See the sample for its exact shape.

Output

One compact JSON value of type boolean. Strings include JSON quotes; arrays preserve the specified order.

Constraints

Array/string lengths are 0 to 10000 unless stated otherwise. Numbers are integers in [-1000000,1000000]; all computed results fit the safe integer range.

Example

Input

17

Output

true

Example 2 input

999983

Output

true

Checks a boundary or contrasting case beyond the public examples.

Public test cases (2)

  • Input

    17

    Expected output

    true
  • Input

    18

    Expected output

    false
Hints (2)
  1. Start with the required output order and the empty-input behavior.
  2. Only divisors through the square root need testing

Target complexity: time O(sqrt(n)) · space O(1)

Your solution

Checking runner availability…

Reference solution

Sign in for solution
All TypeScript programs