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. C# Hadoop学习笔记

    记录一下学习地址 http://www.360doc.com/content/14/0607/22/3218170_384675141.shtml

  2. Swift Explore - 关于 Swift 中的 isEqual 的一点探索

    在我们进行 App 开发的时候,经常会用到的一个操作就是判断两个对象是否相等.比如两个字符串是否相等.而所谓的 相等 有着两层含义.一个是值相等,还有一个是引用相等.如果熟悉 Objective-C ...

  3. [转]IIS部署托管管道模式的集成和经典区别

    关于ESPS和SCSJ在Windows server 2008的问题总结 SCSJ出现的问题在于集成模式和经典模式的选择上,系统本身是没有问题的.我们在部署系统的时候,选择了集成模式,导致WebCon ...

  4. 实体框架 (EF) 入门 => 一、我该用哪个工作流?

    入门的参考资料:http://msdn.microsoft.com/zh-cn/data/ee712907 本篇的参考资料:http://msdn.microsoft.com/zh-cn/data/j ...

  5. 003--VS2013 C++ 多边形绘制

    //全局变量HPEN hPen;HBRUSH hBru;POINT poly1[6], poly2[5], poly3[5]; //---------------------------------- ...

  6. Mysql的相关命令

    1.登录服务器 mysql -h host -u user -p mysql -h host -u user -p 数据库 2.使用SHOW语句找出服务器上当前存在什么数据库:mysql> SH ...

  7. jira的插件

    jira的插件开发流程实践   怎么开头呢,由于自己比较懒,博客一直不怎么弄,以后克己一点,多传点自己遇到的问题和经历上来,供自己以后记忆,也供需要的小伙伴少走点弯路吧 最近公司项目需要竞标一个运维项 ...

  8. UITableView设置cell为不可选?

    本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术.本文将为读者讲解UITableView如何设置单 ...

  9. 标准非STL之bitset

    template <size_t N> class bitset; BitsetA bitset stores bits (elements with only two possible ...

  10. MyEclipse 中的各种有的没的快捷方式

    快捷键1 (CTRL) Ctrl+1 快速修复Ctrl+D: 删除当前行  Ctrl+Q  定位到最后编辑的地方  Ctrl+L  定位在某行   Ctrl+O  快速显示 OutLine  Ctrl ...