This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* user: chertes-cab
* fname: Andrei
* lname: Chertes
* task: Present
* score: 29.0
* date: 2021-12-16 08:14:57.934784
*/
#include <bits/stdc++.h>
using namespace std;
const int maxlen = 25;
bool vis[maxlen + 1];
int st[maxlen + 1];
int mask;
vector<int> v;
bool valid(int p) {
if(p == 1) {
return 1;
}
for(int i = 1; i < p; i++) {
if(!vis[__gcd(st[i], st[p])]) {
return 0;
}
}
return 1;
}
void bkt(int p) {
for(int i = st[p - 1] + 1; i <= maxlen; i++) {
st[p] = i;
vis[i] = 1;
mask += (1 << (i - 1));
if(p <= maxlen && valid(p)) {
v.push_back(mask);
bkt(p + 1);
}
vis[i] = 0;
mask -= (1 << (i - 1));
}
}
int T;
int main() {
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
bkt(1);
sort(v.begin(), v.end());
cin >> T;
while(T--) {
int K;
cin >> K;
if(K == 0) {
cout << "0\n";
continue;
}
int cnt = 0;
for(int i = 0; i < maxlen; i++) {
if(v[K - 1] & (1 << i)) {
cnt++;
}
}
cout << cnt << " ";
for(int i = 0; i < maxlen; i++) {
if(v[K - 1] & (1 << i)) {
cout << (i + 1) << " ";
}
}
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |