#include <bits/stdc++.h>
using namespace std;
long long primokr[100];
void genpo() {
  int i, j, k;
  long long res = 0;
  long long one = 1;
  for (i = 0; i <= 60; i++) primokr[i] = 0;
  for (i = 1; i <= 60; i++) {
    for (j = 1; j < i; j++) {
      if (i % j == 0) {
        primokr[i] += (one << (j - 1)) - primokr[j];
      }
    }
  }
}
class Number {
 public:
  int a[70];
  int digs;
  void getfrom(long long x) {
    digs = 0;
    while (x > 0) {
      a[digs] = x % 2;
      digs++;
      x /= 2;
    }
  }
  long long getnum(int c, int offset) {
    long long res = 0;
    int u = digs - offset;
    int v;
    for (v = 1; v <= c; v++) {
      res *= 2;
      res += a[u - v];
    }
    return res;
  }
  long long first(int c) {
    long long res1, res2;
    res1 = getnum(c, 0);
    res2 = res1;
    int co = 0;
    while (res2 == res1) {
      co += c;
      if (co == digs) break;
      res2 = getnum(c, co);
    }
    if (res2 < res1) res1--;
    return res1;
  }
  void print() {
    for (int i = digs - 1; i >= 0; i--) cout << a[i];
    cout << "\n";
  }
  long long calc() {
    if (digs == 0) return 0;
    long long res = 0;
    long long fir;
    long long one = 1;
    long long p[100];
    int i, j;
    for (i = 0; i < 100; i++) p[i] = 0;
    for (i = 1; i < digs; i++) {
      res += primokr[i];
    }
    for (j = 1; j < digs; j++) {
      if (digs % j == 0) {
        fir = first(j);
        p[j] = fir + 1 - (one << (j - 1));
        for (i = 1; i < j; i++) {
          if (j % i == 0) p[j] -= p[i];
        }
        res += p[j];
      }
    }
    return res;
  }
};
int main() {
  long long n, k, res1, t, z;
  genpo();
  cin >> n >> k;
  Number U, V;
  U.getfrom(n - 1);
  V.getfrom(k);
  t = U.calc();
  z = V.calc();
  cout << z - t << "\n";
  return 0;
}
