Little Sub is about to take a math exam at school. As he is very confident, he believes there is no need for a review.

Little Sub's father, Mr.Potato, is nervous about Little Sub's attitude, so he gives Little Sub a task to do. To his surprise, Little Sub finishes the task quickly and perfectly and even solves the most difficult problem in the task.

Mr.Potato trys to find any possible mistake on the task paper and suddenly notices an interesting problem. It's a problem related to Pascal's Triangle.

The definition of Pascal's Triangle is given below:

The first element and the last element of each row in Pascal's Triangle is , and the -th element of the -th row equals to the sum of the -th and the -th element of the -th row.

According to the definition, it's not hard to deduce the first few lines of the Pascal's Triangle, which is:

 

  

   

    

......

In the task, Little Sub is required to calculate the number of odd elements in the 126th row of Pascal's Triangle.

Mr.Potato now comes up with a harder version of this problem. He gives you many queries on this problem, but the row number may be extremely large. For each query, please help Little Sub calculate the number of odd elements in the -th row of Pascal's Triangle.

Input

There are multiple test cases. The first line of the input contains an integer  (), indicating the number of test cases. For each test case:

The first and only line contains an integer  (), indicating the required row number in Pascal's Triangle.

Output

For each test case, output the number of odd numbers in the -th line.

Sample Input

3
3
4
5

Sample Output

2
4
2

题意:求出杨辉三角第n行的奇数数量

思路:将n先减一,然后求出此时n的二进制中1的数量cnt,2的cnt次方即为答案(注意longlong不要用I64d,要用lld)

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std;
int main(){
int T;
cin>>T; while(T--){
long long int m;
scanf("%lld",&m);
long long int cnt=0;
m-=1;
while(m)
{
cnt++;
m-=m&(-m);
}
long long ans=1ll<<cnt;
printf("%lld\n",ans); }
return 0;
}

ZOJ-Little Sub and Pascal's Triangle(思维规律)的更多相关文章

  1. ZOJ 4081 Little Sub and Pascal's Triangle 题解

    ZOJ 4081 Little Sub and Pascal's Triangle 题解 题意 求杨辉三角第n行(从1开始计数)有几个奇数. 考察的其实是杨辉--帕斯卡三角的性质,或者说Gould's ...

  2. ZOJ - 4081:Little Sub and Pascal's Triangle (结论)

    Little Sub is about to take a math exam at school. As he is very confident, he believes there is no ...

  3. 118. Pascal's Triangle杨辉三角形(全部/一行)

    [抄题]: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  4. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  5. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  6. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  7. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  8. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

  9. LeetCode 119 Pascal's Triangle II

    Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...

随机推荐

  1. Consumer设计-high/low Level Consumer

    1 Producer和Consumer的数据推送拉取方式   Producer Producer通过主动Push的方式将消息发布到Broker n Consumer Consumer通过Pull从Br ...

  2. C++结构体的定义、初始化和引用

    定义: 结构体(struct)是由一系列具有相同类型或不同类型的数据构成的数据集合,也叫结构. 声明一个结构体类型的形式是: struct Student{ //声明一个结构体类型Student in ...

  3. 最新解决VS2017+ Mysql + EF 创建实体数据模型 闪退的办法

    研究下来,就是最新的版本兼容性不好啊. 1.找到MySql管网,下载历史版本: mysql-connector-net-6.9.12 mysql-for-visualstudio-1.2.8 2.Nu ...

  4. review backpropagation

    The goal of backpropagation is to compute the partial derivatives ∂C/∂w and ∂C/∂b of the cost functi ...

  5. Visual Studio 代码格式化插件(等号自动对齐、注释自动对齐等)

    1.下载地址 插件:Code alignment  下载地址 2.介绍 Based on principles borrowed from mathematics and other discipli ...

  6. Bugly集成指南

    官网: https://bugly.qq.com/v2/,用QQ扫码登录即可 1.创建应用,获取APPID 2.自动集成 2.1 在Module的build.gradle文件中添加依赖和属性配置: d ...

  7. chrome安装postman插件

    参考http://www.cnplugins.com/zhuanti/how-to-make-crx-install.html 下载地址:http://www.cnplugins.com/down/p ...

  8. winfrom浏览器控件

    (1)webbrowser 在ie的基础上开发出来的,一般情况下很好用,特殊情况下没法用,一堆坑,h5支持效果不好 使用:直接拖控件就好了 (2)WebKit .NET http://webkitdo ...

  9. MasterPage + UpdatePanel + FileUpload

    上传文件在母版页与Ajax的UpdatePanel的环境进行.由于在母版内使用Ajax,建议使用AjaxControlToolkit.dll组件,去微软官网下载后,并拉入BIN目录中. 然后去web. ...

  10. 解决RegexKitLite导入报错问题

    1.RegexKitLite是什么? RegexKitLite是一个非常方便的处理正则表达式的第三方类库. 本身只有一个RegexKitLite.h和RegexKitLite.m 2.导入RegexK ...