您的位置:首页 > 运维架构

B. New Year and Old Property

2016-01-05 18:20 351 查看
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.

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 = 10012and 1010 = 10102.
Two of them (1012 and 1102)
have the described property.

解题说明:此题是一道进制转换题,求出一段区间中转换为二进制时只含有1个0的数字个数。可以先找到题目输入数据范围内所有这样的数字,然后判断是否在区间范围内。

#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

long long a[2000];

int main()
{
long long c,b;
int i,j,count;
for ( i = 1;i<=60;i++)
{
for (j = 1;j<i;j++)
{
a[(i-2)*(i-1)/2+j] = (long long)(pow(2,i)-pow(2,j-1)-1);
}
}
scanf("%I64d %I64d",&c,&b);
count=0;
for ( i = 1;i<2000;i++)
{
if (a[i]>=c&&a[i]<=b)
{
count++;
}
}
printf("%d\n",count);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: