题目描述:

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.

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 and 1102) have the described property.

题目大意:求a到b中包含的所有的整数二进制只有一个1的数的个数

#include <bits/stdc++.h>
using namespace std;
long long num=0,a,b;
void dfs(long long x,int y)//y代表x的二进制中有几个零
{
// cout<<"x:"<<x<<"\n";
if(x>b)return;//如果超出范围,就返回
else if(x>=a&&y==1)//如果在范围里 并且只有一个零 那个数就加一
{
num++;
}
if(y==0)dfs(x<<1,1);
//如果是二进制里没有零的话(例:1111111),那么左移一位,最后一位就是零了
//所以就直接dfs左移,然后y是1
dfs((x<<1)+1,y);
//除了零在最后还有 零在中间的
//所以在上边基础上再加一 (例:10,左移一位加一:101)
} int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>a>>b;
dfs(1,0);
cout<<num<<endl;
return 0;
}

  

New Year and Old Property :dfs的更多相关文章

  1. 《算法设计手册》面试题解答 第五章:图的遍历 附:DFS应用之找挂接点

    第五章面试题解答 5-31. DFS和BFS使用了哪些数据结构? 解析: 其实刚读完这一章,我一开始想到的是用邻接表来表示图,但其实用邻接矩阵也能实现啊?后来才发现应该回答,BFS用队列实现:DFS可 ...

  2. A Knight's Journey 分类: dfs 2015-05-03 14:51 23人阅读 评论(0) 收藏

    A Knight’s Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34085 Accepted: 11621 ...

  3. 图的遍历:DFS和BFS

    图的遍历一般由两者方式:深度优先搜索(DFS),广度优先搜索(BFS),深度优先就是先访问完最深层次的数据元素,而BFS其实就是层次遍历,每一层每一层的遍历. 1.深度优先搜索(DFS) 我一贯习惯有 ...

  4. Property Distribution(DFS)

    Property Distribution タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H×W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています. ...

  5. POJ2676,HDU4069解决数独的两种实现:DFS、DLX

    搜索实现:解决数独有两种思考策略,一种是枚举当前格能填的数字的种数,这里有一优化策略就是先搜索能填入种数小的格子:另一种是考虑处理某一行(列.宫)时,对于某一个没用过的数字,若该行(列.宫)只有一个可 ...

  6. hadoop2.2编程:DFS API 操作

    1. Reading data from a hadoop URL 说明:想要让java从hadoop的dfs里读取数据,则java 必须能够识别hadoop hdfs URL schema, 因此我 ...

  7. Red and Black(BFS or DFS) 分类: dfs bfs 2015-07-05 22:52 2人阅读 评论(0) 收藏

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  8. 图的两种遍历:DFS&BFS

    DFS和BFS在图中的应用: 图连通性判定:路径的存在性:图中是否存在环:求图的最小生成树:求图的关键路径:求图的拓扑排序. DFS:简单的说,先一直往深处走,直到不能再深了,再从另一条路开始往深处走 ...

  9. 【紫书】Ordering Tasks UVA - 10305 拓扑排序:dfs到底再输出。

    题意:给你一些任务1~n,给你m个数对(u,v)代表做完u才能做v 让你给出一个做完这些任务的合理顺序. 题解:拓扑排序版题 dfs到底再压入栈. #define _CRT_SECURE_NO_WAR ...

随机推荐

  1. java.sql.date和java.util.date的区别和转换

    不同点:java.util.Date是在除了SQL语句的情况下面使用的.java.sql.Date是针对SQL语句使用的,它只包含日期而没有时间部分java.util.Date 是 java.sql. ...

  2. PIE currently adds full or partial support to IE 6 through 8 for the following CSS3 features

    PIE stands for Progressive Internet Explorer. It is an IE attached behavior which, when applied to a ...

  3. APP支付 + 退款(JAVA实现)

    首先,你得先有微信开发平台账号密码还需要开通应用,然后还有微信服务商平台商户版账号(这些我都是给产品经理拿的) 其次我认为你先去看一看微信开发平台的文档!  https://pay.weixin.qq ...

  4. 北京Uber优步司机奖励政策(2月26日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. 成都Uber优步司机奖励政策(1月12日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  6. 宁波Uber优步司机奖励政策(12月14日到12月20日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  7. 6 生成器 yield 协程

    1.生成器 ----> 1 b = [x*2 for x in range(100000000000)] MemoryError: 想生成一个存放很多数据的列表,但是又不想内存占用太多 每次用一 ...

  8. day 10 形态学处理 膨胀

    #-*- coding:utf-8 -*- #1.导入包 import cv2 import numpy as np #2.导入图片 img = cv2.imread('home.jpg',0) #3 ...

  9. 【LG2495】[SDOI2011]消耗战

    [LG2495][SDOI2011]消耗战 题面 洛谷 题解 参考博客 题意 给你\(n\)个点的一棵树 \(m\)个询问,每个询问给出\(k\)个点 求将这\(k\)个点与\(1\)号点断掉的最小代 ...

  10. 06003_redis在Linux上的安装

    1.redis-3.0.0.tar.gz下载链接:redis-3.0.0.tar.gz下载 密码:wpbu 2.安装redis编译的c环境,yum install gcc-c++ : 3.将redis ...