csansoon

P4.14 P34091 Perfect numbers

Oct 24th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool is_perfect(int n) {
  5.     int suma = 1;
  6.     for(int i = 2; i*i <= n; ++i){
  7.         if(n % i == 0) suma += i + n/i;
  8.     }
  9.     if(n != 0 and n != 1) return (suma == n);
  10.     else return false;
  11. }
  12.    
  13. int main(){
  14.     int n;
  15.     cin >> n;
  16.     cout<<is_perfect(n)<<endl;
  17. }
Add Comment
Please, Sign In to add comment