Advertisement
SalmaYasser

Elimination Game

Dec 19th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. int lastRemaining(int n) {
  2.  
  3. int res = 1, move = 1;
  4.  
  5. bool left_right = true;
  6.  
  7. while (n > 1)
  8. {
  9. if (left_right)
  10. res += move;
  11. else
  12. res += (n%2) ? move : 0;
  13. n /= 2;
  14. move *= 2;
  15.  
  16. left_right = !left_right;
  17. }
  18. return res;
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement