fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int next(int n){
  6. if(n<=0) return 0;
  7. int p = 1<<20; // n < 10^6
  8. while(!(p&n)) p >>= 1;
  9. return n^p;
  10. }
  11.  
  12. vector<bool> f(int n){
  13. if (n<=0) return vector<bool>(1,true);
  14. int m = next(n);
  15. vector<bool> v = f(m);
  16. vector<bool> w(v);
  17. w.insert(w.end(), n-1-m-m, false);
  18. w.insert(w.end(), v.begin(), v.end());
  19. return w;
  20. }
  21.  
  22. int main() {
  23. int t;
  24. int n, a;
  25. vector<bool> v;
  26. cin>>t;
  27. while(t--){
  28. cin>>n>>a;
  29. v = f(n-1);
  30. for(bool x: v)
  31. cout<<(x?a:0)<<' ';
  32. cout<<endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5288KB
stdin
16
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
stdout
1 
1 1 
1 0 1 
1 1 1 1 
1 0 0 0 1 
1 1 0 0 1 1 
1 0 1 0 1 0 1 
1 1 1 1 1 1 1 1 
1 0 0 0 0 0 0 0 1 
1 1 0 0 0 0 0 0 1 1 
1 0 1 0 0 0 0 0 1 0 1 
1 1 1 1 0 0 0 0 1 1 1 1 
1 0 0 0 1 0 0 0 1 0 0 0 1 
1 1 0 0 1 1 0 0 1 1 0 0 1 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1