Codeforces Good Bye 2015 B. New Year and Old Property (DFS)

来源:互联网 发布:上海 手表 知乎 编辑:程序博客网 时间:2024/05/16 05:30
B. New Year and Old Property
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The year 2015 is almost over.

Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system —201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation.

Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?

Assume that all positive integers are always written without leading zeros.

Input

The only line of the input contains two integers a andb (1 ≤ a ≤ b ≤ 1018) — the first year and the last year in Limak's interval respectively.

Output

Print one integer – the number of years Limak will count in his chosen interval.

Sample test(s)
Input
5 10
Output
2
Input
2015 2015
Output
1
Input
100 105
Output
0
Input
72057594000000000 72057595000000000
Output
26
Note

In the first sample Limak's interval contains numbers 510 = 1012,610 = 1102,710 = 1112,810 = 10002,910 = 10012 and1010 = 10102. Two of them (1012 and1102) have the described property.


题意:求a到b之间转换为二进制之后的数中含有1个0的数的个数


思路:DFS


总结:刚开始写还害怕TLE,最后没想到没超

ac代码:

#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 60001#define LL long long#define ll __int64#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;ll n,m;ll ans;void dfs(ll x,ll bz){if(x>m)return;if(x>=n&&x<=m&&bz)ans++;if(bz==0)dfs(x*2,1);dfs(x*2+1,bz);}int main(){while(scanf("%I64d%I64d",&n,&m)!=EOF){ans=0;dfs(1,0);printf("%I64d\n",ans);}return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 半岁宝宝不吃药怎么办 1岁宝宝不爱吃药怎么办 2岁吃多了呕吐怎么办啊 小孩吃撑了吐怎么办 三岁宝宝吃太多怎么办 小孩吃撑发烧了怎么办 婆婆不帮忙带孩子怎么办 孩子在中班幼儿园不爱写字怎么办 小孩不愿意上学不愿意写字怎么办 宝妈太内向不喜欢带孩子出门怎么办 宝宝吃饭不带围兜怎么办 宝宝吃饭不喜欢带围兜怎么办 宝宝吃饭不爱带围兜怎么办 孩子不吃肉和菜怎么办 我很恶心我婆婆怎么办 坐月子不喜欢婆婆抱宝宝怎么办 宝宝一写字就哭怎么办 4岁宝宝不爱学习怎么办 4岁宝宝不爱写字怎么办 孩子调皮老师不让上学了怎么办 小学生写字握笔握出剪子来怎么办 儿子6岁不会写字怎么办 宝宝在幼儿园不说话怎么办 孩子上幼儿园不说话怎么办 幼儿写数字不写怎么办 小孩不吃饭怎么办 十个月 十个月小孩不爱吃饭怎么办 十个月的小孩不吃饭怎么办 家长要调幼儿园监控怎么办 自己带孩子婆婆生气怎么办 婆婆老是觉得我奶水不够怎么办 1岁小儿特别懒怎么办 17的孩子很懒怎么办 上大班的孩子不愿写字怎么办 快上中班的小朋友不爱学习怎么办 小学生两边肩膀不平应该怎么办 写字右肩膀疼是怎么办 开车久了肩膀疼怎么办 3岁宝宝撕书怎么办 孩子上幼儿园不爱写字怎么办 一年级小孩不爱做作业怎么办