思路:
直接枚举模拟。
c o d e code code
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 2e6 + 10;
int t;
int n, m;
bool a[MAXN];
int main() {
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
scanf("%d", &t);
for(int i = 1; i <= 1000000; i ++) {
int j = i, o = 0;
while(j != 0) {
if(j % 3 == 1) o ++;
if(j % 3 == 2) o --;
j /= 3;
}
if(o == 0) a[i] = 1;
else a[i] = 0;
}
for(int i = 1000001, k = 0; k <= 100; i ++) {
int j = i, o = 0;
while(j != 0) {
if(j % 3 == 1) o ++;
if(j % 3 == 2) o --;
j /= 3;
}
if(o == 0) a[i] = 1, k ++;
else a[i] = 0;
}
while(t --) {
scanf("%d%d", &n, &m);
for(int j = 1, i = n; j <= m; i ++)
if(a[i]) printf("%d ", i), j ++;
printf("\n");
}
return 0;
}