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

题意:求杨辉三角第i行的奇数个数。

思路:求lucus定理,知道C(N,M)为奇数,当且当N&M=M时。 所以我们求出N的二进制下1的个数num,答案就是2^num.

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int main()
{
int T; ll ans,N;
scanf("%d",&T);
while(T--){
cin>>N; ans=;
if(N==1LL){
cout<<<<endl; continue;
} N--;
int i;
rep(j,,) if((N&(1LL<<j))) ans=ans*;
cout<<ans<<endl;
}
return ;
}

ZOJ - 4081: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. [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, ...

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

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

  4. 【leetcode】Pascal's Triangle II

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

  5. 【leetcode】Pascal's Triangle

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

  6. LeetCode 118 Pascal's Triangle

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

  7. 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 ...

  8. LeetCode - Pascal's Triangle II

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

  9. 【leetcode】Pascal's Triangle I & II (middle)

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

随机推荐

  1. kaggle信用卡欺诈看异常检测算法——无监督的方法包括: 基于统计的技术,如BACON *离群检测 多变量异常值检测 基于聚类的技术;监督方法: 神经网络 SVM 逻辑回归

    使用google翻译自:https://software.seek.intel.com/dealing-with-outliers 数据分析中的一项具有挑战性但非常重要的任务是处理异常值.我们通常将异 ...

  2. ueeditor 百度编译器使用onchange效果

    <script id="editor" type="text/plain" style="width:100%;height:200px;&qu ...

  3. js 日期格式化函数(可自定义)

    js 日期格式化函数 DateFormat var DateFormat = function (datetime, formatStr) { var dat = datetime; var str ...

  4. 3.python函数编程-reduce函数

    reduce将所有数据压缩到一起,得到一个最终的结果. 在python2中可以直接使用,在python3中需要导入 from functools import reduce 自己实现代码: num = ...

  5. 4.2计算字符的ASCII碼

    Q:终端输入一个字符,输出ASCII碼 #include<stdio.h> int main() { char c; printf("input a charscter:&quo ...

  6. C++ Templates 关于程序库的概念和通用工具

    using namespace std所谓的命名空间,就是一种将程序库名称封装起来的方法,它就像在程序库中竖立了一道围墙 标准程序库中有一部分,比如string classes,支持具体的错误处理,它 ...

  7. Centos防火墙设置与端口开放的方法

    Centos升级到7之后,内置的防火墙已经从iptables变成了firewalld.所以,端口的开启还是要从两种情况来说明的,即iptables和firewalld.更多关于CentOs防火墙的最新 ...

  8. Excel 数据读入到DataSet

    using System; using System.Collections.Generic; using System.Linq; using System.Data; using System.I ...

  9. 区分舍入函数fix/round/ceil/floor

    1)fix(n)的意义是取小于n的整数(是向零点舍入的意思是往零的方向上靠),这是一类应用在整数取值上的函数,就如同以前我们所研究的求整问题: 例如:fix(pi)=3 ; fix(3.5)=3;  ...

  10. Ubuntu16.04 安装Tensorflow-CPU

    最近我开始学习深度学习框架Tensorflow,一开始在windows平台下的anaconda下安装,由于anaconda安装几次后navigator打开老是出现闪退的问题,所以决定换个ubuntu下 ...