fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. map<int, bool> states; // default value is False
  7. int MAX_DEPTH = 16;
  8.  
  9. int dfs(int cur, int depth = 0) {
  10. if(depth == MAX_DEPTH) {
  11. return cur - (1<<MAX_DEPTH) + 1;
  12. }
  13.  
  14. if(states[cur] == 0) {
  15. states[cur] = !states[cur];
  16. return dfs(2*cur, depth+1);
  17. }
  18. else {
  19. states[cur] = !states[cur];
  20. return dfs(2*cur+1, depth+1);
  21. }
  22.  
  23. }
  24.  
  25. int main() {
  26. int until = (1LL<<(MAX_DEPTH-1));
  27. vector<int> pos; // 0 indexed
  28. for(int i = 1; i <= until; i++) {
  29. // cout << dfs(1) << ' ';
  30. pos.push_back(dfs(1));
  31. }
  32.  
  33. cout << pos[(12344%until)];
  34. // 12344 instead of 12345 since the sequence is 0 indexed
  35. }
  36.  
Success #stdin #stdout 0.11s 18192KB
stdin
Standard input is empty
stdout
7181