Advertisement
STANAANDREY

rec1

Mar 3rd, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. unsigned long long fact(unsigned x)
  5. {
  6.     if (!x)
  7.         return 1;
  8.     return fact(x - 1) * x;
  9. }
  10.  
  11. unsigned get_sumdiv(unsigned x, unsigned sumdiv)
  12. {
  13.     if (sumdiv == 1)
  14.         return 0;
  15.     if (x % sumdiv == 0)
  16.         return get_sumdiv(x, sumdiv - 1) + sumdiv;
  17.     return get_sumdiv(x, sumdiv - 1);
  18. }
  19.  
  20. unsigned get_sumcif(unsigned x)
  21. {
  22.     if (!x)
  23.         return 0;
  24.     return get_sumcif(x / 10) + (x % 10);
  25. }
  26.  
  27. unsigned get_prodcif(unsigned x)
  28. {
  29.     if (!x)
  30.         return 1;
  31.     return get_prodcif(x / 10) * (x % 10);
  32. }
  33.  
  34. void read(unsigned n)
  35. {
  36.     if (n)
  37.     {
  38.         unsigned x;
  39.         cin >> x;
  40.         cout << "fact: " << fact(x) << '\n';
  41.         unsigned sumdiv = get_sumdiv(x, x / 2);
  42.         cout << "sumdiv: " << sumdiv << '\n';
  43.         if (sumdiv + 1 != x)
  44.             cout << "nu ";
  45.         cout << "e perfect" << '\n';
  46.         cout << "sumacif: " << get_sumcif(x) << '\n' << "prodcif: " << get_prodcif(x) << '\n';
  47.         read(n - 1);
  48.     }
  49. }
  50.  
  51. int main()
  52. {
  53.     unsigned n;
  54.     cin >> n;
  55.     read(n);
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement