#include <bits/stdc++.h>
using namespace std;
long long f(int d) {
  long long res = 0;
  long long dp[100];
  memset(dp, 0ll, sizeof(dp));
  for (int k = 1; k < d; k++)
    if (d % k == 0) {
      res += ((1ll << (k - 1)) - dp[k]);
      int nk = k * 2;
      for (; nk <= d; nk += k) dp[nk] += ((1ll << (k - 1)) - dp[k]);
    }
  return res;
}
bool periodic(long long N, int d) {
  for (int i = 0; i < d; i++)
    if ((d + 1) % (i + 1) == 0) {
      long long num = 0;
      for (int j = 0; j <= d; j++)
        if (N & (1ll << (d - j % (i + 1)))) num ^= (1ll << (d - j));
      if (num == N) return true;
    }
  return false;
}
bool differs(long long a, long long b, int bt, int nb) {
  for (int i = nb; i > bt; i--)
    if ((a & (1ll << i)) != (b & (1ll << i))) return false;
  return (a & (1ll << bt)) < (b & (1ll << bt));
}
long long F(long long N) {
  if (!N) return 0;
  int nd = 0;
  for (; (1ll << nd) <= N; nd++)
    ;
  nd--;
  long long ans = periodic(N, nd);
  for (int d = 2; d <= nd; d++) ans += f(d);
  long long dp[100];
  for (int i = nd - 1; i >= 0; i--) {
    memset(dp, 0ll, sizeof(dp));
    if (N & (1ll << i)) {
      memset(dp, 0ll, sizeof(dp));
      for (int j = 0; j < (nd - i); j++)
        if ((j + 1) < (nd + 1) && (nd + 1) % (j + 1) == 0) {
          long long num = 0;
          for (int k = 0; k <= nd; k++)
            if (N & (1ll << (nd - k % (j + 1)))) num ^= (1ll << (nd - k));
          if (num < N && differs(num, N, i, nd)) {
            ans++;
            for (int k = (j + 1) * 2; k <= (nd + 1); k += (j + 1)) dp[k - 1]++;
          }
        }
      for (int j = (nd - i); j <= nd; j++) {
        if ((j + 1) < (nd + 1) && (nd + 1) % (j + 1) == 0) {
          ans += (1ll << (j - (nd - i))) - dp[j];
          for (int k = (j + 1) * 2; k <= (nd + 1); k += (j + 1))
            dp[k - 1] += (1ll << (j - (nd - i))) - dp[j];
        }
      }
    }
  }
  return ans;
}
int main() {
  long long L, R;
  cin >> L >> R;
  cout << F(R) - F(L - 1) << endl;
  return 0;
}
