Advertisement
lukey106

Untitled

May 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int f[13], cnt;
  4. vector <int> v;
  5.  
  6. int factorial(int n)
  7. {
  8.     if (n == 1 || n == 0)return 1;
  9.     else return n * factorial(n-1);
  10. }
  11.  
  12. int main()
  13. {
  14.     int n;
  15.     cin >> n;
  16.     for (int i = 0; i < 13; i++)
  17.     {
  18.         f[i] = factorial(i+1);
  19.     }
  20.     for (int i = 12; n != 0; i--)
  21.     {
  22.         cnt = 0;
  23.         while (f[i] <= n)
  24.         {
  25.             n -= f[i];
  26.             cnt ++;
  27.         }
  28.         if (cnt > 0)v.push_back(cnt);
  29.     }
  30.     cout << v.size() << '\n';
  31.     reverse(v.begin(), v.end());
  32.     for (auto it : v)
  33.     {
  34.         cout << it << ' ';
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement