#include <bits/stdc++.h>   long long n, t, ans;   short i, j, k;   char cnt, l;   long long C[43][43];   int main() {     scanf( %I64d %I64d , &n, &t);     for (i = 0; (1ll << i) < t; ++i)       ;     if ((1ll << i) ^ t) {       puts( 0 );       return 0;     }     k = i + 1;     for (i = 0; i < 43; ++i) C[0][i] = 1ll;     for (i = 1; i < 43; ++i)       for (j = 1; j <= i; ++j) C[j][i] = C[j - 1][i - 1] + C[j][i - 1];     ++n;     for (cnt = i = 0; (1ll << i) <= n; ++i)       if ((1ll << i) & n) ++cnt;     for (l = i = 0; (1ll << i) <= n; ++i)       if (n & (1ll << i)) {         ++l;         if (k - cnt + l >= 0) ans += C[k - cnt + l][i];       }     if (cnt == k) ++ans;     if (k == 1) --ans;     printf( %I64d n , ans);     return 0;   }   