#include #define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i) #define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i) #define ALL(t) t.begin(), t.end() #define RALL(t) t.rbegin(), t.rend() #define MATINIT(type, row, col, init) \ vector>(row, vector(col, init)); #define Yes(cond) cout << (cond ? "Yes" : "No") << endl; #define YES(cond) cout << (cond ? "YES" : "NO") << endl; using namespace std; using LL = long long; using ULL = unsigned long long; template using VEC = std::vector; template using MAT = std::vector>; void DUMP() { cerr << endl; } template void DUMP(Head &&head, Tail &&... tail) { cerr << head << ", "; DUMP(std::move(tail)...); } template ostream &operator<<(ostream &os, vector &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, set &s) { os << "{"; for (auto p : s) os << p << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, map &m) { os << "{"; for (auto p : m) os << p << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, pair p) { os << "[" << p.first << " " << p.second << "]"; return os; } LL N, K; LL dfs(LL x, LL y, VEC bar) { // DUMP(x, y, bar); if (bar.size() == 0) { if (y - x <= K && x <= y) { return 1; } return 0; } if (y - x > K) return 0; LL cnt = 0; LL t = bar.back(); bar.pop_back(); cnt += dfs(x, y, bar); cnt += dfs(x + (1 << t), y, bar); cnt += dfs(x, y + (1 << t), bar); return cnt; } const LL MAX_N = 1e5; int main() { cin >> N >> K; LL Y = 1; LL X = 0; while (Y <= N) { X += Y; Y <<= 1; } Y += N; // DUMP(X,Y,K); if (Y - X <= K) { cout << "INF" << endl; return 0; } LL bit = 0; VEC bar; while ((1 << bit) <= MAX_N) { if (((1 << bit) & N) == 0) { bar.push_back(bit); } ++bit; } // DUMP(bar); LL ans = dfs(N, N, bar); cout << ans << endl; return 0; }