Codeforences Goodbye 2015 B New Year and Old Property

题目传送门

题意:算出 a,b 中 二进制下,含有 且 只含有10的数 的数目
解题方法:暴力(dfs)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
ll ans;
void dfs(ll x,ll cnt)
{
    if(x>m)return ;
    if(x>=n&&x<=m&&cnt==1)
        ans++;
    if(cnt==0)
        dfs(2*x,1);
    dfs(2*x+1,cnt);
}

int main()
{
    cin>>n>>m;
    ans=0;
    dfs(1,0);
    cout<<ans<<endl;
    return 0;
}
全部评论

相关推荐

Cl_Wg:看牛客匿名贴容易抑郁,白菜就是我的天花板
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务