#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 3e6 + 1000;
const long long mod = 1e9 + 7;
const long double PI = 4 * atan((long double)1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res);
}
long long l, r;
long long calc(long long sz) {
  long long res = (long long)1 << (sz - 1);
  for (long long i = 1; i < sz; i++) {
    if (sz % i == 0) {
      res -= calc(i);
    }
  }
  return (res);
}
long long fff(long long sz, long long lim, long long cnt) {
  long long pre = lim >> (cnt - sz);
  long long ans, boz;
  boz = pre;
  ans = pre - ((long long)1 << (sz - 1));
  for (long long i = 1; i < cnt / sz; i++) {
    boz <<= sz;
    boz |= pre;
  }
  if (boz <= lim) {
    ans++;
  }
  for (long long i = 1; i < sz; i++) {
    if (sz % i == 0) {
      ans -= fff(i, lim, cnt);
    }
  }
  return (ans);
}
long long solve(long long x) {
  if (x == 0) {
    return (0);
  }
  long long sz = log2(x) + 1;
  long long ans = 0;
  for (long long i = 1; i < sz; i++) {
    ans += calc(i);
  }
  ans += fff(sz, x, sz);
  return (x - ans);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> l >> r;
  cout << solve(r) - solve(l - 1);
  return (0);
}
