Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created January 30, 2018 14:52
Show Gist options
  • Save s4553711/f6a71f6aeb57d1c43c105d996b44280e to your computer and use it in GitHub Desktop.
Save s4553711/f6a71f6aeb57d1c43c105d996b44280e to your computer and use it in GitHub Desktop.
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