fork(1) download
  1. #include <stdio.h>
  2.  
  3. t,h;f(l){for(t=l;t&&~t&1<<30;t*=2);for(h=0;t&1<<30&&l&1;t*=2,l/=2)++h;return h<<!!l;}
  4.  
  5. int main(void) {
  6. int arr[] = {0, 1, 8, 23, 31, 103, 127, 1877, 2015, 3167, 0};
  7. int i = 0;
  8. for (; arr[i] != 0 || i == 0; ++i)
  9. printf("%d %d\n", arr[i], f(arr[i]));
  10. }
  11.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
0 0
1 1
8 0
23 2
31 5
103 4
127 7
1877 2
2015 10
3167 4