niyaznigmatullin

Untitled

Apr 3rd, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. long long f(long long n, int k) {
  2.   ++n;
  3.   int bits = __builtin_popcountll(n);
  4.   int cur = 0;
  5.   long long ans = 0;
  6.   while (n > 0) {
  7.     if ((n & 1) == 1) {
  8.       --bits;
  9.       if (k >= bits)
  10.         ans += c[cur][k - bits];
  11.     }
  12.     n >>= 1;
  13.     ++cur;
  14.   }
  15.   return ans;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment