## 代码

#include <bits/stdc++.h>

#define rin(i,a,b) for(int i=(a);i<=(b);++i)
#define irin(i,a,b) for(int i=(a);i>=(b);--i)
#define trav(i,a) for(int i=head[a];i;i=e[i].nxt)
#define Size(a) (int)a.size()
#define pb push_back
#define mkpr std::make_pair
#define fi first
#define se second
#define lowbit(a) ((a)&(-(a)))
typedef long long LL;

using std::cerr;
using std::endl;

LL x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}

int d,c;
LL a,b,n;
std::map<LL,LL> mp1[55],mp2[55][55];

inline LL solve1(LL x,LL y){
LL ret=0;
while(x!=y){
if(x<y)std::swap(x,y);
ret+=x;x>>=1;
}
ret+=x;
return ret;
}

LL dfs1(int x,LL w){
if(w<0)return 0;
if(w>(1ll<<(x+1))-2-x)return 0;
if(!x)return w==0;
if(mp1[x].find(w)!=mp1[x].end())return mp1[x][w];
return mp1[x][w]=dfs1(x-1,w)+dfs1(x-1,w-(1ll<<x)+1);
}

LL dfs2(int l,int r,LL w){
if(l>r)std::swap(l,r);
if(w<0)return 0;
if(w>(1ll<<(l+1))+(1ll<<(r+1))-4-l-r)return 0;
if(!r)return w==0;
if(mp2[l][r].find(w)!=mp2[l][r].end())return mp2[l][r][w];
return mp2[l][r][w]=dfs2(l,r-1,w)+dfs2(l,r-1,w-(1ll<<r)+1);
}

int main(){
while(T--){
LL len=solve1(a,b);
if(c==1){printf("%lld\n",len);continue;}
LL ans=0;
rin(i,0,d-1){
LL k=(1ll<<(i+1))-1,x=len/k;
if(k<=len&&(int)log2((long double)x)+1+i<=d){
ans+=dfs1(i,len%k);
}
}
rin(l,1,d-1)rin(r,1,d-1){
LL k=(1ll<<(l+1))+(1ll<<(r+1))-3,b=(1ll<<r)-1,x=(len-b)/k;
if(k+b<=len&&(int)log2((long double)x)+1+std::max(l,r)<=d){
ans+=dfs2(l-1,r-1,(len-b)%k);
}
}
printf("%lld\n",ans-1);
}
return 0;
}


posted on 2019-05-08 07:48  ErkkiErkko  阅读(185)  评论(0编辑  收藏

• 随笔 - 91
• 文章 - 0
• 评论 - 20