Advertisement
lukey106

Untitled

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