#include <bits/stdc++.h>
using namespace std;
map<int, int> moebius(int n) {
  map<int, int> res;
  vector<int> primes;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      primes.push_back(i);
      while (n % i == 0) n /= i;
    }
  }
  if (n != 1) primes.push_back(n);
  int m = primes.size();
  for (int i = 0; i < (1 << m); i++) {
    int mu = 1;
    int d = 1;
    for (int j = 0; j < m; j++) {
      if (i >> j & 1) {
        mu *= -1;
        d *= primes[j];
      }
    }
    res[d] = mu;
  }
  return res;
}
int digCnt(long long n) {
  int cnt = 0;
  while (n) {
    cnt++;
    n /= 2;
  }
  return cnt;
}
int isPrime(int a) {
  if (a <= 1) return false;
  for (int i = 2; i * i <= a; i++)
    if (a % i == 0) return false;
  return true;
}
const int mu[] = {0, 1,  -1, -1, 0, -1, 1,  -1, 0, 0,  1,  -1, 0, -1, 1,  1,
                  0, -1, 0,  -1, 0, 1,  1,  -1, 0, 0,  1,  0,  0, -1, -1, -1,
                  0, 1,  1,  1,  0, -1, 1,  1,  0, -1, -1, -1, 0, 0,  1,  -1,
                  0, 0,  0,  1,  0, -1, 0,  1,  0, 1,  1,  -1, 0, -1, 1,  0,
                  0, 1,  -1, -1, 0, 1,  -1, -1, 0, -1, 1,  0,  0, 1};
long long getNum(long long n) {
  long long res = 0;
  if (n <= 0) return res;
  int digs = digCnt(n);
  vector<int> v;
  long long tmp = n;
  while (tmp) {
    v.push_back(tmp % 2);
    tmp /= 2;
  }
  reverse(v.begin(), v.end());
  for (int i = 2; i < digs; i++) {
    map<int, int> m = moebius(i);
    for (int k = 1; k < i; k++)
      if (i % k == 0) {
        res -= (1LL << (k - 1)) * (long long)m[i / k];
      }
  }
  map<int, int> m = moebius(digs);
  for (int k = 1; k < digs; k++) {
    if (digs % k == 0) {
      long long cand = 0;
      for (int i = 0; i < k; i++) {
        if (i != 0 && v[i]) {
          cand += (1LL << (k - i - 1));
        }
      }
      long long num = 0;
      for (int i = 0; i < k; i++) {
        if (v[i]) {
          for (int j = i; j < digs; j += k) num |= (1LL << (digs - 1 - j));
        }
      }
      if (num <= n) cand++;
      res -= m[digs / k] * cand;
    }
  }
  return res;
}
int main() {
  long long l, r;
  while (cin >> l >> r) {
    cout << getNum(r) - getNum(l - 1) << endl;
  }
  return 0;
}
