fork(4) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. constexpr unsigned floorlog2(unsigned x)
  5. {
  6. return x == 1 ? 0 : 1+floorlog2(x >> 1);
  7. }
  8.  
  9. constexpr unsigned ceillog2(unsigned x)
  10. {
  11. return x == 1 ? 0 : floorlog2(x - 1) + 1;
  12. }
  13.  
  14.  
  15. int main() {
  16. cout << ceillog2(2) << endl;
  17.  
  18. // your code goes here
  19. return 0;
  20. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1