CodeForces 611B - New Year and Old Property(搜索)
来源:互联网 发布:河北大学网络教育 编辑:程序博客网 时间:2024/06/05 19:58
B. New Year and Old Property
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.
Examples
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.
解题思路:
DFS所有只有一个0的二进制的数即可。
AC代码:
#include<bits/stdc++.h>using namespace std;long long a,b;int cnt = 0;void fun(long long check,bool flag){ if(check > b) return ; if(check>=a && check <= b && flag) cnt++; if(!flag) fun(check<<1,1); fun(check<<1|1,flag);}int main(){ cin>>a>>b; fun(1,0); cout<<cnt; return 0;}
- CodeForces 611B - New Year and Old Property(搜索)
- CodeForces 611 B. New Year and Old Property(水~)
- codeforces-611B-New Year and Old Property
- CodeForces 611B New Year and Old Property(DFS)
- 【Goodbye2015】Codeforces 611B New Year and Old Property【思维】
- codeforces 611B New Year and Old Property
- New Year and Old Property CodeForces
- New Year and Old Property CodeForces
- B. New Year and Old Property
- CodeForces 611B New Year and Old Property【DFS&&模拟位运算】
- 611B. New Year and Old Property【模拟位运算】
- CodeForces 611BNew Year and Old Property
- Codeforces Good Bye 2015 B. New Year and Old Property (DFS)
- codeforces - Goodbye2015B - New Year and Old Property(模拟)
- Codeforences Goodbye 2015 B New Year and Old Property
- cf#gb2015-B - New Year and Old Property-暴力
- codeforces611B. New Year and Old Property
- CodeForces 611BNew Year and Old Property(模拟)
- TCP的三次握手(建立连接)和四次挥手(关闭连接)
- JDK1.7的安装步骤(图解)
- 编译MeshLab(2)—VS中引用Lib文件
- 欢迎使用CSDN-markdown编辑器
- 什么是好的API设计?
- CodeForces 611B - New Year and Old Property(搜索)
- Shell编程中函数部分的相关讲解
- 设计器弹出窗口信息无法显示
- PAT 1043. 输出PATest(20)
- 快速排序
- Retrofit+okhttp 缓存的
- 209. Minimum Size Subarray Sum
- 关于容器的理解
- 开通博客