E - New Year and Old Property
2017-09-20 15:53
344 查看
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 and b (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.
Example
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 and 1010 = 10102. Two of them (1012 and 1102) have the described property.
题目大意 :求一个区间里转换成二进制数,其中只有一个0 的二进制数有多少。(其实可以暴力全部求出来,然后看那一个区间里有几个)
#include<stdio.h> #include<string.h> long long ans = 0; long long l,r; void dfs(long long x,int flag) { if(x>r) return; if(x>=l&&x<=r&&flag==1) ans++; if(flag==0) dfs(x*2,1);//找到只有一个0的,flag变成1 dfs(x*2+1,flag);//继续接着往下找 } int main() { scanf("%lld %lld",&l,&r); dfs(1,0); printf("%lld\n",ans); return 0; }
相关文章推荐
- Good Bye 2015-New Year and Old Property(二进制暴力枚举)
- codeforces - Goodbye2015B - New Year and Old Property
- cf#gb2015-B - New Year and Old Property-暴力
- CF Good Bye 2015 B- New Year and Old Property(CF611B)
- New Year and Old Property CodeForces - 611B
- New Year and Old Property CodeForces - 611B
- Codeforences Goodbye 2015 B New Year and Old Property
- B. New Year and Old Property
- 【Goodbye2015】Codeforces 611B New Year and Old Property【思维】
- [CF611B]New Year and Old Property(dfs)
- CodeForces 611B - New Year and Old Property(搜索)
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
- Good Bye 2015 B. New Year and Old Property —— dfs 数学
- CodeForces 611 B. New Year and Old Property(水~)
- codeforces-611B-New Year and Old Property
- 【codeforces 750E】New Year and Old Subsequence
- Codeforces Round #452 E. New Year and Old Subsequence
- [Codeforces 750E]New Year and Old Subsequence
- B. New Year and North Pole
- 750A New Year and Hurry