Easy C++ Sol : There is no odd perfect number


  • 0
    P
    bool checkPerfectNumber(int num) {
    	if (num % 2 != 0) return false;
    	int sum = 1;
    	for (int i = 2; i <= num / 2; i++)
    	{
    		if (num%i == 0)
    		{
    			sum = sum + i;
    			if (sum>num) return false;
    		}
    	}
    	if (sum == num)
    		return true;
    
    	return false;
    }

Log in to reply
 

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