Created
January 30, 2018 14:52
-
-
Save s4553711/f6a71f6aeb57d1c43c105d996b44280e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool checkPerfectNumber(int num) { | |
int result = 1; | |
for(int i = 2; i < sqrt(num); i++) { | |
if (num%i == 0) { | |
//cout << result << ", " << i << endl; | |
result += i + num/i; | |
} | |
} | |
return result == num && num != 1 ? true: false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment