Language: C++

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	register int x=0,f=1;register char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline void write(int x){
    if(x<0)x=-x,putchar('-');
    if(x>9)write(x/10);
	putchar(x%10+'0');
}
#define rg register
const int maxn=110;
long long a,b,x,y,l,r,ans,ll,rr;
int aa[maxn],bb[maxn],lena,lenb,len,k;
int main(){
    read(a),read(b);x=a,y=b;
    while(a)aa[++lena]=a&1,a>>=1;
    while(b)bb[++lenb]=b&1,b>>=1;
    for(rg int i=max(lena,lenb);i;i--){
        if(aa[i]!=bb[i]){
            len=i;break;
        }
        x-=1ll*aa[i]<<(i-1);
        y-=1ll*bb[i]<<(i-1);
    }
    for(rg int i=len-1;i;i--)
        if(bb[i]){
            k=i;break;
        }
    l=x;r=(1ll<<(len-1))+(1ll<<k)-1;
    ll=(1ll<<(len-1))+x;rr=(1ll<<len)-1;
    if(ll>r)ans=r-l+1+rr-ll+1;
    else ans=rr-l+1;
    printf("%lld\n",ans);
}

Compiler output:
a.cc: In function 'int read()':
a.cc:4:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 |         register int x=0,f=1;register char ch=getchar();
      |                      ^
a.cc:4:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 |         register int x=0,f=1;register char ch=getchar();
      |                          ^
a.cc:4:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 |         register int x=0,f=1;register char ch=getchar();
      |                                            ^~
a.cc: In function 'int main()':
a.cc:19:9: error: no matching function for call to 'read(long long int&)'
   19 |     read(a),read(b);x=a,y=b;
      |     ~~~~^~~
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:371:16: note: candidate: 'ssize_t read(int, void*, size_t)'
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
/usr/include/unistd.h:371:16: note:   candidate expects 3 arguments, 1 provided
a.cc:3:12: note: candidate: 'int read()'
    3 | inline int read(){
      |            ^~~~
a.cc:3:12: note:   candidate expects 0 arguments, 1 provided
a.cc:19:17: error: no matching function for call to 'read(long long int&)'
   19 |     read(a),read(b);x=a,y=b;
      |             ~~~~^~~
/usr/include/unistd.h:371:16: note: candidate: 'ssize_t read(int, void*, size_t)'
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
/usr/include/unistd.h:371:16: note:   candidate expects 3 arguments, 1 provided
a.cc:3:12: note: candidate: 'int read()'
    3 | inline int read(){
      |            ^~~~
a.cc:3:12: note:   candidate expects 0 arguments, 1 provided
a.cc:22:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   22 |     for(rg int i=max(lena,lenb);i;i--){
      |                ^
a.cc:29:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   29 |     for(rg int i=len-1;i;i--)
      |                ^