#include <bits/stdc++.h>
using namespace std;
long long mu[65];
long long dp[65];
void precalc() {
  mu[1] = 1;
  for (int i = 2; i < 65; ++i) {
    mu[i] = 1;
    int ii = i;
    for (int j = 2; j <= ii; ++j) {
      if (ii % j != 0) continue;
      ii /= j;
      mu[i] *= -1;
      if (ii % j == 0) {
        mu[i] = 0;
        break;
      }
    }
  }
  dp[1] = 2;
  for (int i = 2; i < 65; ++i) {
    for (int j = 2; j <= i; ++j) {
      if (i % j) continue;
      dp[i] += -mu[j] * (1LL << (i / j));
    }
  }
}
long long calc(long long x) {
  if (x == 0) return 0;
  string s = "";
  while (x > 0) s += char('0' + (x & 1)), x >>= 1;
  reverse(s.begin(), s.end());
  long long res = 0;
  int n = s.size();
  long long add = 0;
  for (int len = 1; len <= n; ++len) {
    string cur = s.substr(0, len);
    if (len < s.size() && s[len] == '0') continue;
    if (cur.size() < n) cur += '0';
    while (cur.size() < n) cur += '?';
    for (int i = 1; i < n; ++i) {
      if (n % i != 0) continue;
      bool ok = true;
      for (int j = i; j < n; ++j)
        if (!(cur[j] == '?' || cur[j - i] == '?' || cur[j] == cur[j - i]))
          ok = false;
      if (!ok) continue;
      int cnt = 0;
      for (int j = 0; j < i; ++j) cnt += cur[j] == '?';
      add += (1 << cnt) * -mu[n / i];
    }
  }
  return add;
}
long long get(long long x) {
  int len = 0;
  long long res = calc(x);
  while (x > 0) {
    x >>= 1;
    ++len;
  }
  for (int i = len - 1; i >= 2; --i) res += calc((1LL << i) - 1);
  return res;
}
int main() {
  precalc();
  long long l, r;
  cin >> l >> r;
  cout << get(r) - get(l - 1);
  return 0;
}
