fork(2) download
  1. #include <iostream>
  2. #include <iterator> // for ostream_iterator
  3. #include <vector>
  4.  
  5. int n, x;
  6. std::vector<int> a = std::vector<int>(), b = std::vector<int>();
  7.  
  8. int main() {
  9. std::cin >> n >> x;
  10. for (int i = 1; i <= n && x; ++i) {
  11. switch (x % 3) {
  12. case 1: b.push_back(i); break;
  13. case 2: a.push_back(i); break;
  14. }
  15. x = (x + 1)/3;
  16. }
  17. if (x) { std::cout << -1; return 0; }
  18. std::copy(a.begin(), a.end(), std::ostream_iterator<int>(std::cout, " "));
  19. std::cout << "\n";
  20. std::copy(b.begin(), b.end(), std::ostream_iterator<int>(std::cout, " "));
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 3460KB
stdin
10 5
stdout
1 2 
3