codeforces Good Bye 2015 B

B. New Year and Old Property
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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 = 1012610 = 1102710 = 1112810 = 10002910 = 10012 and 1010 = 10102. Two of them (1012 and 1102) have the described property.


题意:

给你[l,r],让你判断从[l,r]的数转化为二进制之后只有1位二进制为0的有多少个

思路:枚举二进制有几位(都转化为全是1的二进制),然后枚举二进制的哪一位变为0,,判断这个数是不是在[l,r]的范围内。

#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf -0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;

int main(){
    ll a,b;
    scanf("%I64d%I64d",&a,&b);
    ll ans=0;
    for(int i=2;i<=61;i++){
        ll num=(1LL<<i)-1;
        for(int j=0;j<i-1;j++)
            if(num-(1LL<<j)>=a&&num-(1LL<<j)<=b){
                //printf("%I64d\n",num-(1LL<<j));
                ans++;
            }
    }
    printf("%I64d\n",ans);
}

你可能感兴趣的:(codeforces Good Bye 2015 B)