#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int Mod = 998244353;
long long bit(long long x, int l, int r) { return (x >> l) & ((1LL << r) - 1); }
long long solve3(long long x, int n, int k) {
  long long y = bit(x, n - k, k);
  for (int i = n - k; i >= 0; i -= k)
    if (bit(x, i, k) != y) {
      if (bit(x, i, k) < y) y--;
      break;
    }
  return max(0LL, y - (1LL << k - 1) + 1);
}
long long solve2(long long x, int n) {
  if (n == 1) return 0;
  vector<long long> primes;
  int m = n;
  for (int i = 2; i * i <= m; i++)
    if (m % i == 0) {
      primes.push_back(i);
      while (m % i == 0) m /= i;
    }
  if (m > 1) primes.push_back(m);
  m = primes.size();
  long long One = solve3(x, n, 1);
  long long res = One;
  for (int mask = 1; mask < (1 << m); mask++) {
    long long num = 1;
    int cnt = 0;
    for (int i = 0; i < m; i++)
      if (mask & 1 << i) num *= primes[i], cnt++;
    if (num == n) continue;
    res += (cnt & 1 ? 1 : -1) * (solve3(x, n, n / num) - One);
  }
  return res;
}
long long solve1(long long x) {
  if (x == 0) return 0;
  int n = 0;
  for (int i = 0; x >> i; i++)
    if (x >> i & 1) n = i + 1;
  long long res = solve2(x, n);
  for (int i = 2; i < n; i++) res += solve2((1LL << i) - 1, i);
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long l, r;
  cin >> l >> r;
  long long rr = r;
  cout << solve1(r) - solve1(l - 1) << endl;
  return 0;
}
