Unable to find mistake in Simple enough

#include< bits/stdc++.h>

using namespace std;

int generate(int s,int e,int l,int r, int n){

// when s=e and in range of l and r
if((s==e)&&(s>=l&&s<=r)){

    return n%2;
}

//no overlap

if(s>r||e<l){

return 0;

}

// complete overlap or partial

int mid=(s+e)/2;
int left=generate(s,mid-1,l,r,n/2);
int right=generate(mid+1,e,l,r,n/2);

return left+right+(n%2&&(s<=l&&r<=e));

}

int main()
{
long long int n,l,r,count=0;

cin>>n>>l>>r;
int e=int(ceil(log2(n)));
 e=1<<e;
 e=e-2;
int s=generate(0,e,l,r,n);

cout<<s;
return 0;

}

l and r are given 1 indexed, so take s and e as 1 indexed also.
e is incorrect!, it should be 2^(logN+1)
also

here you should check for mid only.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.