#include <bits/stdc++.h>
using namespace std;
long long dfs2(int n) {
  long long ret = 1LL << (n - 1);
  for (int i = 1; i < n; i++) {
    if (n % i == 0) ret -= dfs2(i);
  }
  return ret;
}
long long dfs1(long long n) {
  if (n <= 2) return 0;
  vector<int> b;
  long long x = n;
  for (; x;) b.push_back(x & 1), x >>= 1;
  reverse(b.begin(), b.end());
  long long ret = 0;
  for (int i = 1; i <= b.size(); i++) {
    if (b.size() % i == 0) {
      int k = b.size() / i;
      if (k < 2) break;
      long long now = 0, rnow = 0;
      for (int j = 0; j < i; j++) now <<= 1, now += b[j];
      for (int j = 0; j < k; j++) rnow <<= i, rnow += now;
      if (rnow > n) now--;
      if (now & (1LL << (i - 1)))
        ret = ret + now - (1 << (i - 1)) + 1 - dfs1(now);
    }
  }
  return ret;
}
long long calc(long long n) {
  if (n < 3) return 0;
  vector<int> b;
  long long x = n;
  for (; x;) b.push_back(x & 1), x >>= 1;
  reverse(b.begin(), b.end());
  long long ret = 0;
  for (int i = 1; i <= b.size(); i++) {
    for (int k = 2; k * i <= b.size(); k++) {
      if (k * i < b.size()) {
        ret += dfs2(i);
      } else {
        long long now = 0, rnow = 0;
        for (int j = 0; j < i; j++) now <<= 1, now += b[j];
        for (int j = 0; j < k; j++) rnow <<= i, rnow += now;
        if (rnow > n) now--;
        if (now & (1LL << (i - 1)))
          ret = ret + now - (1 << (i - 1)) + 1 - dfs1(now);
      }
    }
  }
  return ret;
}
int main() {
  long long l, r;
  while (cin >> l >> r) {
    cout << calc(r) - calc(l - 1) << endl;
  }
  return 0;
}
