import static java.util.Arrays.deepToString;

import java.io.*;
import java.util.*;

public class stones_nn {

	static final int MAXBITS = 60;
	static final long MAXN = 1000000000 * 1000000000L;
	static final int MOD = 1000000007;

	static void solve() throws Exception {
		long n = nextLong();
		long k = nextLong();
		assert 1 <= n && n <= MAXN;
		assert 1 <= k && k <= MAXN;
		int ans = solve(n, k);
		out.println(ans);
	}

	static int solve(long n, long k) {
		long[] ones = new long[MAXBITS];
		for (int i = 0; i < ones.length; i++) {
			ones[i] = (1L << i + 1) - 1;
		}
		List<Long> numbers = new ArrayList<Long>();
		for (int i = 0; i < MAXBITS; i++) {
			for (int j = 0; j <= i; j++) {
				long e = ones[i] ^ (ones[j] >> 1);
				if (e <= k) {
					numbers.add(e);
				}
			}
		}
		numbers.add(n);
		boolean[][] a = new boolean[MAXBITS][numbers.size()];
		boolean[][] b = new boolean[MAXBITS][numbers.size() - 1];
		for (int i = 0; i < numbers.size(); i++) {
			long m = numbers.get(i);
			for (int j = MAXBITS - 1; j >= 0; j--) {
				a[j][i] = (m & 1) == 1;
				if (i < b[j].length) {
					b[j][i] = (m & 1) == 1;
				}
				m >>= 1;
			}
		}
		int ra = rg(a);
		int rb = rg(b);
		if (ra != rb) {
			return 0;
		}
		int pow = numbers.size() - 1 - ra;
		int ans = 1;
		for (int i = 0; i < pow; i++) {
			ans += ans;
			if (ans >= MOD) {
				ans -= MOD;
			}
		}
		return ans;
	}

	static int rg(boolean[][] a) {
		int start = 0;
		int m = a[0].length;
		int n = a.length;
		for (int i = 0; start < n && i < m; i++) {
			for (int j = start; j < n; j++) {
				if (a[j][i]) {
					boolean[] t = a[j];
					a[j] = a[start];
					a[start] = t;
					break;
				}
			}
			if (!a[start][i]) {
				continue;
			}
			for (int j = start + 1; j < n; j++) {
				if (!a[j][i]) {
					continue;
				}
				for (int k = i; k < m; k++) {
					a[j][k] ^= a[start][k];
				}
			}
			start++;
		}
		return start;
	}

	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;

	static void debug(Object... a) {
		System.err.println(deepToString(a));
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null) {
				return null;
			}
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}

	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		try {
			File file = new File("stones.in");
			InputStream input = System.in;
			OutputStream output = System.out;
			if (file.canRead()) {
				input = (new FileInputStream(file));
				output = (new PrintStream("stones.out"));
			}
			br = new BufferedReader(new InputStreamReader(input));
			out = new PrintWriter(output);
			solve();
			out.close();
			br.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
