想下递归过程
注意位运算优先级小,加括号
View Code
#include<stdio.h>
int k;
int dfs(int left)
{
if((left-k)<=1||((left-k)%2)==1)
{
return 1;
}
return dfs((left-k)>>1)+dfs(left-((left-k)>>1));
}
int main()
{
int n;
while(scanf("%d%d",&n,&k)!=EOF)
{
printf("%d\n",dfs(n));
}
}