Advertisement
STANAANDREY

pb30 14/1/2020

Jan 14th, 2020
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int pr(int x)
  5. {
  6.     if (x % 2 == 0 || x == 1)
  7.         return 0;
  8.  
  9.     for (int d = 3; d * d <= x; d += 2)
  10.         if (x % d == 0)
  11.             return 0;
  12.     return 1;
  13. }
  14.  
  15. int sdiv(int x)
  16. {
  17.     int s = 0;
  18.     for (int d = 1; d * d <= x; d++)
  19.         if (x % d == 0)
  20.         {
  21.             s += d;
  22.             if (d != x / d)
  23.                 s += x / d;
  24.         }
  25.     return s;
  26. }
  27.  
  28.  
  29.  
  30. int main()
  31. {
  32.     int n;
  33.     cin >> n;
  34.     for (int x = 0; x <= n; x++)
  35.         if (pr(sdiv(x)))
  36.             cout << x << ' ';
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement