import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int a = Integer.parseInt(first[0]); int b = Integer.parseInt(first[1]); if ((a & b) != a) { System.out.println(0); return; } int x = a ^ b; int count = 0; while (x > 0) { if (x % 2 == 1) { count++; } x /= 2; } long[][] comb = new long[count][count]; for (int i = 0; i < count; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) { comb[i][j] = 1; } else { comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; } } } long total = 0; for (int i = 1; i < count; i++) { int base = count - i; for (int j = 0; j <= base; j++) { total += comb[base][j]; } } System.out.println(total); } }