A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.

Given an integer n, return true if n is a perfect number, otherwise return false.

&nbsp;
Example 1:

Input: num = 28
Output: true
Explanation: 28 = 1 + 2 + 4 + 7 + 14
1, 2, 4, 7, and 14 are all divisors of 28.


Example 2:

Input: num = 7
Output: false


&nbsp;
Constraints:


	1 &lt;= num &lt;= 108


class Solution:
    def checkPerfectNumber(self, num: int) -> bool:
        sum = 0
        root = num**0.5  
        if num ==1:
            return False
        for i in range(2,int(root)+1):
            if num%i== 0:
                sum +=(num//i)+i
        return sum+1 == num
class Solution {
    public boolean checkPerfectNumber(int num) {
        if(num==1)
        return false;

        int sum = 1;
        for(int i=2; i<Math.sqrt(num); i++){
            if(num%i==0){
            sum += i + num / i;
            }
        }
        if(sum==num){
        return true;
        }
        else{
        return false;
        }
    }
}
class Solution {
public:
    bool checkPerfectNumber(int num) {
    // we are initialising sum with 1 instead of 0 because 1 will be divisor of every number
        int sum=1;
        for(int i=2; i<sqrt(num); i++){
            if(num%i==0){
            // it checks if both are same factors, for ex, if num=9, i=3, num/i is also equal to 3. It is done so that repeated factors aren't added.
                if(i==num/i){
                    sum += i;
                }
                else{
                // we are adding n/i because since we are running the loop for sqrt(num), we will be missing divisors >sqrt(num) so tto include that factor we'll add num/i; for ex if we have 64 as number than 8 is sqrt but 16 and 32 also divides 64 but our loop won't consider that case; so we are adding num/i, which means with 2 we are adding 32 and with 4 we are adding 16.
                    sum += i + num/i;
                }
            }
        }
        if(sum==num && num!=1){
            return true;
        }
        return false;
    }
};
    /**
 * @param {number} num
 * @return {boolean}
 */
var checkPerfectNumber = function(num) {
    let total = 0

    for(let i = 1 ; i < num;i++){
        if(num % i == 0){
            total += i
        }
    }
    return total == num ? true : false
};
Perfect Number