-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF_elephant_1.cpp
More file actions
55 lines (50 loc) · 982 Bytes
/
F_elephant_1.cpp
File metadata and controls
55 lines (50 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include<vector>
#include <istream>
#include<iomanip>
#include<stack>
using namespace std;
#define ll long long
ll to_dm(string &s) {
ll k = 1;
ll ans = 0;
for (int i = s.size() - 1; i >= 0; i--) {
ans = ans + (s[i] - '0') * k;
k = k * 2;
}
return ans;
}
int main(){
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // _DEBUG
int n, k;
cin >> n >> k;
string s ="";
for (int i = 0; i < k; i++) {
s += '1';
}
for (int i = k; i < 30; i++) {
s += '0';
}
reverse(s.begin(), s.end());
vector<int>ans;
do {
ll k = to_dm(s);
if (k <= n)
ans.push_back(k);
else
break;
} while (next_permutation(s.begin(), s.end()));
cout << ans.size() << endl;
for (int i = 0; i < ans.size() && i < 1000; i++) {
cout << ans[i] << endl;
}
return 0;
}