#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &m, const T &v) {
  if (v > m) return m = v, true;
  return false;
}
template <typename T>
bool chmin(T &m, const T &v) {
  if (v < m) return m = v, true;
  return false;
}
template <typename T>
bool chinc(T &v1, T &v2) {
  if (v1 > v2) return swap(v1, v2), true;
  return false;
}
template <typename T>
bool chdec(T &v1, T &v2) {
  if (v1 < v2) return swap(v1, v2), true;
  return false;
}
namespace fio {
static const char eof = '\xff';
struct Cg {
  inline char operator()() {
    char c = (char)getchar();
    if (c == eof) valid = false;
    return c;
  };
  bool valid = true;
};
struct Cp {
  inline void operator()(int x) { putchar(x); }
};
struct Ce {
  inline void operator()(int x) { putc(x, stderr); }
};
inline bool IS(char x) {
  return x == ' ' || x == '\r' || x == '\n' || x == '\t';
}
template <class T>
struct Fr {
  T P;
  inline Fr &operator,(int &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(long long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(unsigned &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(unsigned long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(unsigned long long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(float &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (c == '.') {
      double u = 0.1;
      for (c = P(); c >= '0' && c <= '9'; c = P(), u *= 0.1) x += u * (c - '0');
    };
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(double &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (c == '.') {
      double u = 0.1;
      for (c = P(); c >= '0' && c <= '9'; c = P(), u *= 0.1) x += u * (c - '0');
    };
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(long double &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (c == '.') {
      double u = 0.1;
      for (c = P(); c >= '0' && c <= '9'; c = P(), u *= 0.1) x += u * (c - '0');
    };
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(char &x) {
    for (x = P(); IS(x);) x = P();
    return *this;
  }
  inline Fr &operator,(char *s) {
    for (*s = P(); IS(*s) && P.valid;) *s = P();
    for (; !IS(*s) && P.valid;) *++s = P();
    *s = 0;
    return *this;
  }
  inline Fr &operator,(string &s) {
    s.clear();
    char c = P();
    for (; IS(c) && P.valid;) c = P();
    for (; !IS(c) && P.valid;) s.push_back(c), c = P();
    return *this;
  }
  inline operator bool() { return P.valid; }
};
template <class T>
struct Fw {
  T P;
  char B[32];
  inline Fw &operator,(int x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(long long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(unsigned x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(unsigned long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(unsigned long long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator()(float g, int d) {
    if (d) {
      double t = 0.5;
      for (int i = d; i--;) t *= 0.1;
      if (g < 0) P('-'), g = -g;
      g += t;
      *this, (long long)(g);
      P('.');
      g -= floor(g);
      while (d--) {
        g *= 10;
        int i = (int)floor(g);
        P(i + '0');
        g -= i;
      }
    } else
      *this, (g > 0 ? (long long)(g + 0.5) : (long long)(g - 0.5));
    return *this;
  }
  inline Fw &operator()(double g, int d) {
    if (d) {
      double t = 0.5;
      for (int i = d; i--;) t *= 0.1;
      if (g < 0) P('-'), g = -g;
      g += t;
      *this, (long long)(g);
      P('.');
      g -= floor(g);
      while (d--) {
        g *= 10;
        int i = (int)floor(g);
        P(i + '0');
        g -= i;
      }
    } else
      *this, (g > 0 ? (long long)(g + 0.5) : (long long)(g - 0.5));
    return *this;
  }
  inline Fw &operator()(long double g, int d) {
    if (d) {
      double t = 0.5;
      for (int i = d; i--;) t *= 0.1;
      if (g < 0) P('-'), g = -g;
      g += t;
      *this, (long long)(g);
      P('.');
      g -= floor(g);
      while (d--) {
        g *= 10;
        int i = (int)floor(g);
        P(i + '0');
        g -= i;
      }
    } else
      *this, (g > 0 ? (long long)(g + 0.5) : (long long)(g - 0.5));
    return *this;
  }
  inline Fw &operator,(char x) {
    P(x);
    return *this;
  }
  typedef basic_ostream<char, char_traits<char>> &OS;
  typedef basic_istream<char, char_traits<char>> &IS;
  inline Fw &operator,(OS &(*func)(OS)) {
    if (func == static_cast<OS &(*)(OS)>(endl<char, char_traits<char>>))
      P('\n');
    return *this;
  }
  inline Fw &operator,(IS &(*func)(IS)) {
    if (func == static_cast<IS &(*)(IS)>(ws<char, char_traits<char>>)) P(' ');
    return *this;
  }
  inline Fw &operator,(const char *s) {
    for (; *s; ++s) P(*s);
    return *this;
  }
  inline Fw &operator,(const string &s) {
    (*this), s.c_str();
    return *this;
  }
  template <class C>
  inline Fw &all(const C &v, char sep = ' ', char nl = '\n') {
    auto it = v.begin();
    for (int i = 0; i < (int)v.size(); ++i, ++it) {
      if (i && sep) P(sep);
      (*this), *it;
    }
    if (nl) P(nl);
    return *this;
  }
  template <class U>
  inline Fw &print(U x) {
    (*this), x;
    P('\n');
    return *this;
  }
  template <class U, class... Us>
  inline Fw &print(U x, Us... args) {
    (*this), x;
    P(' ');
    print(args...);
    return *this;
  }
};
}  // namespace fio
fio::Fr<fio::Cg> fin;
fio::Fw<fio::Cp> fout;
fio::Fw<fio::Ce> ferr;
static const int maxb = 64;
int64_t solve(int64_t num) {
  vector<vector<int64_t>> cnt(maxb, vector<int64_t>(maxb));
  int64_t ans = 0;
  int len = 0;
  while (num > ((1LL << len) - 1)) ++len;
  ;
  for (int cyc_len = 1; cyc_len < len; ++cyc_len) {
    for (int cyc_cnt = 1; cyc_cnt * cyc_len <= len; ++cyc_cnt) {
      int tot_len = cyc_len * cyc_cnt;
      if (cyc_cnt * cyc_len == len) {
        int64_t hi = num >> (cyc_len * (cyc_cnt - 1));
        int64_t temp = 0;
        for (int i = 0, iend = cyc_cnt; i < iend; i++)
          temp = (temp << cyc_len) | hi;
        if (temp > num) --hi;
        cnt[tot_len][cyc_len] += (hi - (1LL << (cyc_len - 1))) + 1;
      } else {
        cnt[tot_len][cyc_len] += 1LL << (cyc_len - 1);
      }
    }
  }
  for (int tot_len = 1, tot_lenend = maxb - 1; tot_len <= tot_lenend;
       tot_len++) {
    for (int i = 1; i <= tot_len; ++i)
      if (tot_len % i == 0) {
        for (int j = i + i; j <= tot_len; j += i)
          if (tot_len % j == 0) {
            cnt[tot_len][j] -= cnt[tot_len][i];
          }
        if (i < tot_len) ans += cnt[tot_len][i];
      }
  };
  return ans;
}
int main() {
  int64_t l, r;
  fin, l, r;
  fout, solve(r) - solve(l - 1), endl;
  return 0;
}
