A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true" or "false" respectively). And every decimal number has a binary representation which is actually a series of bits. If a bit of a number is 1 and its next bit is also 1 then we can say that the number has a 1 adjacent bit. And you have to find out how many times this scenario occurs for all numbers up to N.

Examples:

Number         Binary          Adjacent Bits

12                    1100                        1

15                    1111                        3

27                    11011                      2

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case contains an integer N (0 ≤ N < 231).

Output

For each test case, print the case number and the summation of all adjacent bits from 0 to N.

Sample Input

7

0

6

15

20

21

22

2147483647

Sample Output

Case 1: 0

Case 2: 2

Case 3: 12

Case 4: 13

Case 5: 13

Case 6: 14

Case 7: 16106127360

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len,l,r;
LL f[][][];
int d[];
int zhan[],top;
inline LL dfs(int now,int dat,int tot,int fp)
{
if (now==)return tot;
if (!fp&&f[now][dat][tot]!=-)return f[now][dat][tot];
LL ans=,mx=fp?d[now-]:;
for (int i=;i<=mx;i++)
{
if (i==)ans+=dfs(now-,,tot,fp&&i==d[now-]);
else ans+=dfs(now-,,tot+(dat==),fp&&i==d[now-]);
}
if (!fp)f[now][dat][tot]=ans;
return ans;
}
inline LL calc(LL x)
{
if (x<=)return ;
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=d[len];i++)sum+=dfs(len,i,,i==d[len]);
return sum;
}
main()
{
int T=read(),cnt=;
while (T--)
{
r=read();
if (r<l)swap(l,r);
memset(f,-,sizeof(f));
printf("Case %d: %lld\n",++cnt,calc(r));
}
}

LightOj 1032

[暑假集训--数位dp]LightOj1032 Fast Bit Calculations的更多相关文章

  1. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  2. [暑假集训--数位dp]hdu3709 Balanced Number

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

  3. [暑假集训--数位dp]hdu3555 Bomb

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...

  4. [暑假集训--数位dp]hdu3652 B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...

  5. [暑假集训--数位dp]hdu2089 不要62

    杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...

  6. [暑假集训--数位dp]hdu5787 K-wolf Number

    Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...

  7. [暑假集训--数位dp]UESTC250 windy数

    windy定义了一种windy数. 不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数. windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数? Inp ...

  8. [暑假集训--数位dp]LightOJ1140 How Many Zeroes?

    Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...

  9. [暑假集训--数位dp]hdu5898 odd-even number

    For a number,if the length of continuous odd digits is even and the length of continuous even digits ...

随机推荐

  1. Django 模板函数

    Django 模板函数 在模板中的函数是只需要函数名,不用加括号,自动执行 在前端中的函数 不用加括号,函数自动执行 前端 {% for item in userinfo.keys %} <h3 ...

  2. iOS 多线程编程

    参考文章: iOS多线程编程之NSThread的使用http://blog.csdn.net/totogo2010/article/details/8010231 iOS多线程编程之NSOperati ...

  3. 【转】Matlab的regionprops详解

    matlab函数_连通区域 1. matlab函数bwareaopen──删除小面积对象格式:BW2 = bwareaopen(BW,P,conn)作用:删除二值图像BW中面积小于P的对象,默认情况下 ...

  4. 有重复元素的排列(DFS)

    题目描述: 设R={ r1, r2 , …, rn}是要进行排列的n个元素.其中元素r1, r2 , …, rn均为小写字母并且可能相同.试设计一个算法,列出R的所有不同排列. 给定n 以及待排列的n ...

  5. IntelliJ IDEA 配置 Tomcat 运行web项目

    运行前提: 配置好 Java 的运行环境 配置好 Tomcat 安装 IntelliJ IDEA 开始 1.创建项目并配置 关于配置SDK,等建完项目再说 没有配置SDK的话 会出现下面的弹框,点击 ...

  6. java中的final关键字(2013-10-11-163 写的日志迁移

     final关键字:修饰符,表示最后的.最终的    修饰类: 表示该类不能派生子类(不能被继承)   1.当不希望父类的的某个方法被子类覆盖(override)时,可以用final关键字来修饰.   ...

  7. jQuery将物体居中,并且转换显示和隐藏

    今天来给大家贴一段代码,代码的作用就是利用jQuery将物体居中,并且转换显示和隐藏: 首先建立一个div标签并且写好css样式,具体如下 然后我想要的效果是当我点击了button这个按钮,test可 ...

  8. ubuntu中卸载没有安装完全的软件包

    sudo apt-get autoclean sudo apt-get clean sudo apt-get autoremove

  9. 安装ubuntu16.4后

    美化及配置: http://www.fant0m.com/18.html 安装pip: $ wget https://bootstrap.pypa.io/get-pip.py $ python get ...

  10. PHP-redis命令之 列表(lists)

    三.列表(lists) 1.lpush:将所有指定的值插入到存于 key 的列表的头部.如果 key 不存在,那么在进行 push 操作前会创建一个空列表. 如果 key 对应的值不是一个 list ...