#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double PI = acos(-1.0);
string bin(long long x) {
  if (x == 0) return "0";
  if (x == 1) return "1";
  return bin(x >> 1) + ((x & 1) ? '1' : '0');
}
vector<string> split(string s, int len) {
  string ts = "";
  vector<string> vs;
  for (int i = 0; i < s.length(); i += len) {
    ts = "";
    for (int j = 0; j < len; ++j) ts += s[i + j];
    vs.push_back(ts);
  }
  return vs;
}
bool cmp(string a, string b) {
  for (int i = 0; i < a.length(); ++i)
    if (a[i] != b[i]) {
      if (a[i] != '?' && b[i] != '?') return 0;
    }
  return 1;
}
long long gg(string s, int len) {
  int n = (int)s.length();
  len = n / len;
  vector<string> sp = split(s, len);
  for (int i = 0; i < sp.size(); ++i)
    if (!cmp(sp[0], sp[i])) return 0;
  int ct = 0;
  for (int i = 0; i < sp[0].length(); ++i)
    if (sp[0][i] == '?') ++ct;
  return 1LL << ct;
}
bool ok(string s) {
  int n = (int)s.length();
  for (int i = 2; i <= n; ++i)
    if (n % i == 0) {
      int len = n / i;
      vector<string> sp = split(s, len);
      bool ff = 1;
      for (int j = 0; j < sp.size(); ++j)
        if (cmp(sp[0], sp[j]) == 0) ff = 0;
      if (ff) return 1;
    }
  return 0;
}
long long f(int len) {
  vector<int> p;
  int c = len;
  for (int i = 2; i * i <= c; ++i)
    if (c % i == 0) {
      p.push_back(i);
      while (c % i == 0) c /= i;
    }
  if (c != 1) p.push_back(c);
  long long r = 0;
  int n = (int)p.size();
  for (int i = 0; i < (1 << n); ++i) {
    int tp = 1, ct = 0;
    for (int j = 0; j < n; ++j)
      if (i & (1 << j)) ++ct, tp *= p[j];
    if (tp != 1) r += (ct % 2 ? 1 : -1) * (1LL << (len / tp));
  }
  return r / 2;
}
long long gao(string s) {
  vector<int> p;
  int c = (int)s.length();
  for (int i = 2; i * i <= c; ++i)
    if (c % i == 0) {
      p.push_back(i);
      while (c % i == 0) c /= i;
    }
  if (c != 1) p.push_back(c);
  long long r = 0;
  int n = (int)p.size();
  for (int i = 0; i < (1 << n); ++i) {
    int tp = 1, ct = 0;
    for (int j = 0; j < n; ++j)
      if (i & (1 << j)) ++ct, tp *= p[j];
    if (tp != 1) {
      r += (ct % 2 ? 1 : -1) * gg(s, tp);
    }
  }
  return r;
}
long long count(long long x) {
  if (!x) return 0;
  string s = bin(x), pre = s;
  int n = (int)s.length();
  long long ans = 0;
  for (int i = 0; i < n; ++i) pre[i] = '?';
  for (int i = 0; i < n; ++i) {
    pre[i] = s[i] - 1;
    long long add = 0;
    if (!i) {
      for (int j = 2; j < n; ++j) ans += f(j), add += f(j);
    } else if (s[i] == '1') {
      add = gao(pre);
      ans += gao(pre);
    }
    pre[i] = s[i];
  }
  return ans + ok(s);
}
int main() {
  long long l, r;
  while (cin >> l >> r) {
    cout << count(r) - count(l - 1) << endl;
  }
  return 0;
}
