1 #include <iostream>
2 #include <vector>
3 #include <algorithm>
4 #include <iterator>
5 #define LL long long
6
7 using namespace std;
8
9 class LittleElephantAndPermutationDiv2{
10 public:
11 LL getNumber(int N, int k){
12 LL res = 0;
13 vector<int> a(N);
14 for(int i = 0 ; i < N; ++ i ){
15 a[i] = i + 1;
16 }
17 do{
18 LL value = 0;
19 for(int i = 0; i < N; ++ i){
20 value += max(a[i],i+1);
21 }
22 if( value >= k ) ++res;
23 copy(a.begin(),a.end(),ostream_iterator<int>(cout," "));
24 cout<<endl;
25 }while(next_permutation(a.begin(),a.end()));
26 cout<<res<<endl;
27 for(int i = 1; i<= N; ++ i) res *= i;
28 return res;
29 }
30 };