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. 使用SharedPreferences接口来实现记住密码功能

    SharedPreferences接口非常适合用来存储零散的数据.这里我们用来实现记录用户名和密码的功能.在前面我用过IO流来实现记住密码的功能.那么用SharedPreferences接口会比用IO ...

  2. Oracle merge into 语句进行insert或者update操作,如果存在就update,如果不存在就insert

    merge into的形式:    MERGE INTO [target-table] A USING [source-table sql] B ON([conditional expression] ...

  3. sequelize 测试

    1.在根目录新建module文件,在文件下新建文件modelhead.js 代码如下: var Sequelize=require("sequelize") var sequeli ...

  4. c++ 类中模版成员函数

    C++函数模版与类模版. template <class T> void SwapFunction(T &first, T &second){ }//函数模版 templa ...

  5. python-ASCII与Unicode

    # Auther: Aaron Fan'''ASCII:不支持中文,1个英文占1个字节Unicode(万国码,支持所有国家的文字显示):支持中文,但是每个英文和中文都占2个字节UTF-8(是一种针对U ...

  6. SDUT 3402 数据结构实验之排序五:归并求逆序数

    数据结构实验之排序五:归并求逆序数 Time Limit: 40MS Memory Limit: 65536KB Submit Statistic Problem Description 对于数列a1 ...

  7. python常见的加密解密

    #!/usr/bin/env python ''' Python Crypto Wrapper - By Chase Schultz Currently Supports: AES-256, RSA ...

  8. mybatis spring maven

    maven版本:3.3.9  解压即可使用 spring版本:4.3.9  通过maven进行管理下载 mybatis版本:3.4.4 通过maven进行管理下载 mysql版本:5.7  conne ...

  9. 论道HTML5 PDF扫描版

    论道HTML5先简要介绍了如何用HTML5和CSS3制作网站,然后全面介绍了API和Canvas2D,接着介绍了如何在手机浏览器上开发HTML5相关的应用.WebSocketAPI相关的三个案例和时下 ...

  10. jQuery的Validate插件

    http://www.runoob.com/jquery/jquery-plugin-validate.html 项目中的:: $(function () { $('#createDepartment ...