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. javaScript之NodeList

    NodeList对象 是DOM操作取出的集合(实际上是基于DOM结构动态查询的结果),用来保存一组有序的节点,可以通过位置来访问这些节点,它并不是array的实例. Nodelist最大的特点就是它的 ...

  2. 【272】ArcPy处理数据

    参考:ArcPy 函数列表(按字母顺序) 参考:在arcgis上用python脚本(arcpy)做数据批处理 1. 导入 ArcPy,定义 Workspace >>> import ...

  3. 关联查询 join的使用

    #!/usr/bin/env python import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.dec ...

  4. mysql 5.7.11 源码安装

    mysql5.711安装 1.安装boost包下载地址http://sourceforge.net/projects/boost/files/boost/ 2.解压boost_1_59_0.tar.g ...

  5. Linux 大页面使用与实现简介(转)

    引言 随着计算需求规模的不断增大,应用程序对内存的需求也越来越大.为了实现虚拟内存管理机制,操作系统对内存实行分页管理.自内存“分页机制”提出之始,内存页面的默认大小便被设置为 4096 字节(4KB ...

  6. 高性能MySQL笔记-第4章Optimizing Schema and Data Types

    1.Good schema design is pretty universal, but of course MySQL has special implementation details to ...

  7. java开发中用到的技术(持续更新.....)

    一.数据库 1.数据库连接池:当jdbc连接数据库使用DriverManager 获取时,每次向数据库建立连接的时候都要讲connection加载到内存中,当同时使用的用户数量较大时,会造成服务器不堪 ...

  8. Luogu 3332 [ZJOI2013]K大数查询

    BZOJ 3110 很早就想写的试炼场题. 不会整体二分啊呜呜呜,只能写写树套树. 有一个trick就是外层使用一个权值线段树,把位置作为下标的线段树放在内层,这样子的话我们在查询$k$大的时候就可以 ...

  9. Linux-shell获取天气

    用Linux中的shell获取天气,本来觉的比较难,原来,真简单,个位数的代码就搞定. 获取对应城市天气 所有天气信息都从中国天气网获取.每一个城市多会对应一个id(比如,北京为101010100,因 ...

  10. C++笔记--模板

    一个string模板 简单的定义 template <class C>//模板形式,C是一个类型名字,不一定是某个类的名字 class String{ struct srep; srep ...