easy +8 pts

Deficient Number Check

Check if a positive integer is deficient by comparing proper divisor sums.

A positive integer n is called **deficient** if the sum of its **proper divisors** (all positive divisors of n excluding n itself) is **less than** n. For example, 8 is deficient because its proper divisors are 1, 2, 4, and 1+2+4=7 < 8. The number 6 is **not** deficient because 1+2+3=6 (it is perfect), and 12 is **not** deficient because 1+2+3+4+6=16 > 12 (it is abundant). Write a function `is_deficient(n: int) -> bool` that returns `True` if n is deficient and `False` otherwise. You may assume n is a positive integer (n >= 1). The function should handle edge cases such as n=1. The proper divisor sum of 1 is 0 (since it has no divisors other than itself), so 1 is deficient.

Constraints

1 <= n <= 10^6. The function should run in O(sqrt(n)) time or better.

Example

>>> is_deficient(8)
True
>>> is_deficient(6)
False
>>> is_deficient(12)
False
>>> is_deficient(1)
True
8 points ~8 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

A proper divisor of n is any divisor d of n with d < n.
Check divisibility up to the square root of n and add both divisors when found.
Be careful not to add n itself; also avoid adding the same divisor twice when n is a perfect square.
For n=1, the sum is 0, so return True.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.