B. New Year and Old Property
 

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.

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个0的数 的数目

题解:   对于  10110010  枚举每一位为0所带来的答案就好了

或者你可以数位dp

//meek
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include<map>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair const int N=+;
const ll INF = 1ll<<;
const int inf = ;
const int MOD= ; int d[N];
int sum[N];
ll solve(ll n) {
if(n<) return ;
ll tmp = n;
int len = ; mem(sum);
while(tmp) d[++len]= tmp%,tmp/=;
for(int i=len;i>=;i--) sum[i] = sum[i+] +d[i]; ll ans = ;
int f= ;
for(int i=;i<=len;i++) {
if((!f||d[i])&&sum[i+]==len-i) {
ans+=(len-i);//cout<<ans<<endl;
}
else ans+=(len-i==?:(len-i-));
if(d[i] == )f=;
// cout<<ans<<endl;
}
return ans;
}
int main() {
ll a,b;
scanf("%lld%lld",&a,&b);
printf("%lld\n",solve(b)-solve(a-));
// printf("%lld\n",);
return ;
}

代码

Good Bye 2015 B. New Year and Old Property 计数问题的更多相关文章

  1. Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP

    B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The y ...

  2. Good Bye 2015 B. New Year and Old Property —— dfs 数学

    题目链接:http://codeforces.com/problemset/problem/611/B B. New Year and Old Property time limit per test ...

  3. codeforces Good Bye 2015 B. New Year and Old Property

    题目链接:http://codeforces.com/problemset/problem/611/B 题目意思:就是在 [a, b] 这个范围内(1 ≤ a ≤ b ≤ 10^18)统计出符合二进制 ...

  4. good bye 2015 B - New Year and Old Property

    题意:统计在n,m之间的数的二进制表示形式只有一个零的数目. 位运算模拟+dfs #include<iostream> #include<string> #include< ...

  5. Good Bye 2015 D. New Year and Ancient Prophecy

    D. New Year and Ancient Prophecy time limit per test 2.5 seconds memory limit per test 512 megabytes ...

  6. Good Bye 2015 A. New Year and Days 签到

    A. New Year and Days   Today is Wednesday, the third day of the week. What's more interesting is tha ...

  7. Codeforces Good Bye 2015 A. New Year and Days 水题

    A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...

  8. Good Bye 2015 C. New Year and Domino 二维前缀

    C. New Year and Domino   They say "years are like dominoes, tumbling one after the other". ...

  9. Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp

    D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...

随机推荐

  1. 各设备如何清理dns缓存

    Windows 按下 Windows+R 键,运行 cmd ,在命令提示符运行命令 ipconfig /flushdns OS X 10.10 在[应用程序][实用工具][终端]运行命令 sudo d ...

  2. SVN基于一个branch创建新branch

    在本地现有Branch(Checkout出来的目录)上,右键SVN,选择Branch/Tags,选择目录.比如https://sadcsc01.pmmr.com/web/Jaguar/branches ...

  3. Thread系列——Thread.Sleep(0)

    转载自:http://www.cnblogs.com/ATually/archive/2010/10/21/1857261.html 线程这一概念,可以理解成进程中的一个小单元.这个单元是一个独立的执 ...

  4. 46.谈谈SDRAM的作用

    SDRAM这个至今还在用的存储器,虽然被后来的DDR取代,掌握好它还是很重要的.之前在调试时,确实费了好大劲,它的复杂性毋庸置疑,一般人要想弄懂他,得花1个月左右吧,至少我这么认为.话说回来,SDRA ...

  5. 26.68013 烧录方式 及iic生成

    硬件程序烧录 1)因为本产品要求将二进制代码和硬件PID/VID烧录在EEPROM,而不是使用CYPRESS推荐的在线下载方式,所以外部采用了8K的EEPROM.上电后68013A会将EEPROM中的 ...

  6. JAVA事务

    一.什么是事务 我们通常会认为事务与数据库有关. 事务是访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数据库的操作.事务的正确执行使得数据库从一种状态转换成另外一种状态. 事务必须服从IS ...

  7. RHEL 6.4中解决xx用户不在sudoers列表,此事将被报告的问题

    1.使用sudo service iptables status命令时报告没有权限: [tansheng@localhost ~]$ sudo service iptables status [sud ...

  8. Ant学习---第二节:Ant添加文件夹和文件夹集的使用

    一.创建 java 项目(Eclipse 中),结构图如下: 1.创建 .java 文件,代码如下: package com.learn.ant; public class HelloWorld { ...

  9. saltstack知识点

    1.salt '*' sys.doc 显示minion设备上支持的命令   2.salt-call 可以显示比salt更多的信息,可以用来调试,检查,如果需要更详细的信息使用 salt-call -l ...

  10. 浅谈对git的认识

    在上大二之前我根本不知道git是什么,根本不知道它有什么功能,以及应用于那个领域,那天老师说让我们了解一些它,并对其进行一下学习.我瞬间就蒙了,但是我并没有把其抛在脑后,而是通过在其它方式,对其进行了 ...