my c++ code


  • 0
    D

    class Solution {
    public:
    bool checkPerfectNumber(int num) {
    if (num <= 1)
    return false;

        int sum = 1;
        for (int i = 2; i * i <= num; i++)
        {
            if (num % i == 0)
            {
                sum += i;
                if (i * i != num)
                    sum += num / i;
            }
        }
        return sum == num;
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.