1952. Three Divisors
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 63% Topics: Math, Enumeration, Number Theory
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(sqrt(n))
# Space: O(1)
class Solution(object):
def isThree(self, n):
"""
:type n: int
:rtype: bool
"""
cnt = 0
i = 1
while i*i <= n and cnt <= 3:
if n%i == 0:
cnt += 1 if i*i == n else 2
i += 1
return cnt == 3
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions