Three Divisors - Problem
Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false.
An integer m is a divisor of n if there exists an integer k such that n = k * m.
Input & Output
Example 1 — Perfect Square of Prime
$
Input:
n = 4
›
Output:
true
💡 Note:
4 = 2², and 2 is prime. The divisors of 4 are: 1, 2, 4 (exactly 3 divisors)
Example 2 — Not a Square of Prime
$
Input:
n = 6
›
Output:
false
💡 Note:
The divisors of 6 are: 1, 2, 3, 6 (4 divisors, not 3)
Example 3 — Another Square of Prime
$
Input:
n = 9
›
Output:
true
💡 Note:
9 = 3², and 3 is prime. The divisors of 9 are: 1, 3, 9 (exactly 3 divisors)
Constraints
- 1 ≤ n ≤ 104
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given integer n to analyze
2
Count Divisors
Find all positive divisors of n
3
Check Count
Return true if exactly 3 divisors found
Key Takeaway
🎯 Key Insight: Only perfect squares of prime numbers have exactly 3 divisors: 1, the prime, and its square
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code