Counter game Time : O(logn) Space : O(1) 12345678910string counterGame(long n) { bool louise = true; while(n != 1) { long lg = log2(n); if(1ll<<lg == n) n>>=1; else n -= 1ll<<lg; louise = !louise; } return !louise ? "Louise" : "Richard";}