B. New Year and Old Property
来源:互联网 发布:淘宝店铺名片怎么分享 编辑:程序博客网 时间:2024/05/18 02:07
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.
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.
Print one integer – the number of years Limak will count in his chosen interval.
5 10
2
2015 2015
1
100 105
0
72057594000000000 72057595000000000
26
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;}
- B. New Year and Old Property
- 611B. New Year and Old Property【模拟位运算】
- Codeforences Goodbye 2015 B New Year and Old Property
- cf#gb2015-B - New Year and Old Property-暴力
- CodeForces 611 B. New Year and Old Property(水~)
- codeforces-611B-New Year and Old Property
- CodeForces 611B New Year and Old Property(DFS)
- CodeForces 611B - New Year and Old Property(搜索)
- 【Goodbye2015】Codeforces 611B New Year and Old Property【思维】
- codeforces 611B New Year and Old Property
- codeforces611B. New Year and Old Property
- New Year and Old Property CodeForces
- New Year and Old Property CodeForces
- Codeforces Good Bye 2015 B. New Year and Old Property (DFS)
- CF Good Bye 2015 B- New Year and Old Property(CF611B)
- CodeForces 611B New Year and Old Property【DFS&&模拟位运算】
- codeforces - Goodbye2015B - New Year and Old Property(模拟)
- CodeForces 611BNew Year and Old Property
- Nginx的安装与配置(一)
- qq 飞信中无法切换输入法
- angular教程
- javascript可以访问到到cookie么
- Arduino 中断和定时器
- B. New Year and Old Property
- Ubuntu14.04下python数据处理环境搭建
- feature scaling的作用
- 单例设计模式
- Headset offers virtual reality you can control with your hands
- 初识vbulletin
- 利用dom4j解析xml--天气预报
- Apache Commons Lang包比较常用的项目
- arch安装vmware tools