Advertisement
RadioNurshat

Perfect Number

Sep 27th, 2020 (edited)
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5. bool dividersSum(int n) {
  6.     int nn = n;
  7.     int result = 0;
  8.     for (int i = n-1; i > 1; i--) {
  9.         if (n % i == 0) {
  10.             result += i;
  11.         }
  12.     }
  13.     return result + 1 == nn;
  14. }
  15. int main()
  16. {  
  17.     setlocale(LC_ALL, "ru");
  18.     int n;
  19.     cin >> n;
  20.     if (dividersSum(n)) {
  21.         cout << "СОВЕРШЕННОЕ";
  22.     }
  23.     else {
  24.         cout << "НЕ СОВЕРШЕННОЕ";
  25.     }
  26. }
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement