Advertisement
darrellp

CountSteps

Nov 25th, 2021
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.15 KB | None | 0 0
  1. int CountSteps(int n)
  2. {
  3.     if (n <= 0)
  4.     {
  5.         return 0;
  6.     }
  7.    
  8.     int ret = 0;
  9.     while (n != 1)
  10.     {
  11.         ret += 1 + (n & 1);
  12.         n >>= 1;
  13.     }
  14.     return ret + 1;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement