Monday, September 11, 2017

507. Perfect Number

https://leetcode.com/problems/perfect-number/description/

if(num == 1) return false;
        int s = 1, N = sqrt(num);
        for(int i=2; i<=N;i++) {
            if(num%i == 0) s += i + num/i;
        }
        if(s == num) return true;
        return false;
    }

No comments:

Post a Comment