Abundant and Deficient Classifier - Problem

Given a positive integer, classify it as abundant, deficient, or perfect based on the sum of its proper divisors.

Definitions:

  • Proper divisors: All positive divisors of a number except the number itself
  • Abundant: Sum of proper divisors > number
  • Deficient: Sum of proper divisors < number
  • Perfect: Sum of proper divisors = number

Additionally, find and list the first 20 numbers of each type.

For a single number classification, return the classification as a string. For finding the first 20 of each type, return an object with arrays for each classification.

Input & Output

Example 1 — Perfect Number
$ Input: n = 6
Output: perfect
💡 Note: Proper divisors of 6 are [1, 2, 3]. Sum = 1 + 2 + 3 = 6, which equals the number itself, so 6 is perfect.
Example 2 — Abundant Number
$ Input: n = 12
Output: abundant
💡 Note: Proper divisors of 12 are [1, 2, 3, 4, 6]. Sum = 1 + 2 + 3 + 4 + 6 = 16, which is greater than 12, so 12 is abundant.
Example 3 — Deficient Number
$ Input: n = 8
Output: deficient
💡 Note: Proper divisors of 8 are [1, 2, 4]. Sum = 1 + 2 + 4 = 7, which is less than 8, so 8 is deficient.

Constraints

  • 1 ≤ n ≤ 106
  • n is a positive integer

Visualization

Tap to expand
INPUTALGORITHMRESULT12Number to classify1Find all proper divisors2Check 1 to √12 for divisors3Sum: 1 + 2 + 3 + 4 + 6 = 164Compare 16 with 12Divisors: 1, 2, 3, 4, 6Sum = 16ABUNDANT16 > 12Sum of proper divisorsexceeds the number💡Key Insight:Finding divisors up to √n and their pairs eliminates redundant checking while maintaining accuracy.TutorialsPoint - Abundant and Deficient Classifier | Square Root Optimization
Asked in
Google 15 Microsoft 12 Amazon 8
23.4K Views
Medium Frequency
~15 min Avg. Time
842 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen