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. 关于TCP长连接和发送心跳的一些理解

    原因 TCP是一种有连接的协议,但是这个连接并不是指有一条实际的电路,而是一种虚拟的电路.TCP的建立连接和断开连接都是通过发送数据实现的,也就是我们常说的三次握手.四次挥手.TCP两端保存了一种数据 ...

  2. 把旧系统迁移到.Net Core 2.0 日记(11) -- Authentication 认证 claimsIdentity 对比 之前的FormAuthentication

    实现最简单的认证,类似之前的FormAuthentication 在 Startup 的 ConfigureServices() 方法中添加 Authentication 的配置: 这个CookieA ...

  3. summary_16th Nov, 2018

    一. 编程语言的分类: a. 机器语言:直接使用二进制指令去编写程序,必须考虑硬件细节 b:汇编语言:用英文标签取代二进制指令去编写程序,必须考虑硬件细节 c:高级语言:用人类能理解的方式编写程序,通 ...

  4. QuickStart系列:docker部署之Mysql

    这里配置只做开发用,生产环境请根据需要修改或自行搜索其他说明 使用docker安装mysql,目前版本5.7.4(当前时间 2018.1.11) 环境 vm: Centos7 镜像来源 https:/ ...

  5. JAVA项目之苹果IAP内购JAVA服务器验证流程详解

    1.前言 本博客是经历过多个项目检验的, 绝对真实, 适应于对苹果iap内购稍微有些了解的JAVA开发人员,  认真看,  定能完美解决苹果内购问题. 苹果IAP内购支付实际上是"将客户端支 ...

  6. url 传参数时出现中文乱码该怎么解决

    一般出现乱码都是在js裏面跳转到哪个类 然後得到这个参数的时候中文乱码,有一个非常实用的办法,在js你可以这样写:var url=........;url=encodeURI(url); url=en ...

  7. python 学习 模块

    在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就越来越长,越来越不容易 维护, 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少,很 ...

  8. 第一篇 入门必备 (Android学习笔记)

    第一篇 入门必备 第1章 初识Android 第2章 搭建你的开发环境 第3章 创建第一个程序--HelloWorld 第4章 使用Android工具   ●Android之父 Android安迪·罗 ...

  9. python常见面试题(mark)

    1.大数据的文件读取 ① 利用生成器generator ②迭代器进行迭代遍历:for line in file 2.迭代器和生成器的区别 1)迭代器是一个更抽象的概念,任何对象,如果它的类有next方 ...

  10. 用swagger生成接口文档代码

    1.Swagger2类: package com.example.demo; import com.google.common.base.Predicate; import io.swagger.an ...