← Back to challenges

Exactly Three

JavaScriptHardalgebramathnumbersvalidation

Instructions

You are given a number n. Determine whether n has exactly 3 divisors or not.

Examples

isExactlyThree(4) ➞ true
// 4 has only 3 divisors: 1, 2 and 4

isExactlyThree(12) ➞ false
// 12 has 6 divisors: 1, 2, 3, 4, 6, 12

isExactlyThree(25) ➞ true
// 25 has only 3 divisors: 1, 5, 25

Notes

1 ≤ n ≤ 10^12

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.