Check the Sum of Proper Positive Divisors

Quick Overview

Check the Sum of Proper Positive Divisors. A positive integer is perfect when the sum of all its positive divisors smaller than itself equals the integer.

Check the Sum of Proper Positive Divisors

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem A positive integer is perfect when the sum of all its positive divisors smaller than itself equals the integer. Return whether num has this property. ```cpp class Solution { public: bool checkPerfectNumber(int num); }; ``` ### Examples **Example 1:** ```text num = 6 Output: true Explanation: Its proper divisors are 1, 2 and 3, whose sum is 6. ``` **Example 2:** ```text num = 12 Output: false Explanation: 1+2+3+4+6 = 16. ``` ### Constraints - The input num is an integer from 1 through 100000000. ### Clarifying Questions Exclude the number itself and avoid counting a square-root divisor twice. ```hint Read the boundary condition How can factor pairs replace scanning every smaller positive integer? ``` ### Contract considerations Exclude the number itself and avoid counting a square-root divisor twice.

Overview: Check the Sum of Proper Positive Divisors. A positive integer is perfect when the sum of all its positive divisors smaller than itself equals the integer.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
1
0

Problem

A positive integer is perfect when the sum of all its positive divisors smaller than itself equals the integer. Return whether num has this property.

class Solution {
public:
    bool checkPerfectNumber(int num);
};

Examples

Example 1:

num = 6
Output: true
Explanation: Its proper divisors are 1, 2 and 3, whose sum is 6.

Example 2:

num = 12
Output: false
Explanation: 1+2+3+4+6 = 16.

Constraints

  • The input num is an integer from 1 through 100000000.

Clarifying Questions Guidance

Exclude the number itself and avoid counting a square-root divisor twice.

Contract considerations

Exclude the number itself and avoid counting a square-root divisor twice.