fork(1) download
  1. #include <stdio.h>
  2.  
  3. long long NumberOfA(long long x)
  4. {
  5. long long t = x <<1;
  6. while(t^(t&-t)) t ^= (t&-t);
  7. return t-++x;
  8. }
  9.  
  10. unsigned long long NA2(long long x)
  11. {
  12. unsigned long long y = ((((unsigned long long)x)-1)+1) >> 1;
  13. return y;
  14. }
  15.  
  16.  
  17.  
  18. int main(void) {
  19.  
  20. long long x = 10000000000;
  21.  
  22. printf("X:%lld => N(a):%lld; N2(a):%llu\n", 10LL, NumberOfA(10LL), NA2(10LL));
  23. printf("X:%lld => N(a):%lld; N2(a)%llu\n", x, NumberOfA(x), NA2(x));
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
X:10 => N(a):5; N2(a):5
X:10000000000 => N(a):7179869183; N2(a)5000000000