HDU 5694 BD String 递归暴力
http://blog.csdn.net/angon823/article/details/51484906
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long LL; LL solve(LL x){ if(x<=0)return 0; LL cur=1,ret=0; while(cur<x){ cur=cur*2+1; } cur=(cur-1)/2; ret=(cur+1)/2; LL res=x-cur-1; return ret+1+res-(ret-solve(cur-res)); } int main(){ int T; scanf("%d",&T); while(T--){ LL l,r; scanf("%I64d%I64d",&l,&r); printf("%I64d\n",solve(r)-solve(l-1)); } return 0; }