Leetcode Problem 1952. Three Divisors

1952. Three Divisors

Leetcode Solutions

Check for Three Divisors using Square Root

  1. Calculate the square root of n and store it in a variable sqrt.
  2. Check if sqrt multiplied by itself equals n.
    • If not, return false because n is not a perfect square.
  3. Iterate from 2 to sqrt - 1.
    • If sqrt is divisible by any of these numbers, return false because sqrt is not a prime number.
  4. If no divisors are found, return true because n is a square of a prime number and has exactly three divisors.
UML Thumbnail

Brute Force Divisor Counting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...