ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle

简介: ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle

Hazard and The Triangle


Time Limit: 1 Second      Memory Limit: 262144 KB      Score: 1


I'm Eden Hazard,the so-called "superb passer". In a match in the group stage,three players surrounding me tried to block my advance,which,of course,failed. However,at that moment,they formed a triangle,which reminds me of an interesting problem about Pascal's triangle.


The first element and the last element of each row in a 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.Here's an example.


image.png


I wonder how many elements in the -th row of a Pascal's Triangle are odd numbers.


Input


There are several test cases (no more than ).

There is an integer  in each case.


Output


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


Input


3
4
5

Output

2
4
2

Output


解题思路:杨辉三角第 n 行的奇数个数,2^( n-1 中二进制 1 的个数)。

AC 代码


#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll numOf1(ll n)
{
    ll cnt = 0;
    while(n){
        cnt++;  // 只要 n 不为 0,则其至少有一个 1
        n = n & (n - 1);
    }
    return cnt;
}
int main()
{
    ll n;
    while(~scanf("%lld",&n))
    {
        if(n<=0) puts("0");
        else cout<<(1LL<<NumberOf1(n-1))<<endl;
    }
    return 0;
}
目录
相关文章
|
12月前
|
图形学
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
69 0
AtCoder Beginner Contest 176 D - Wizard in Maze(01BFS)
AtCoder Beginner Contest 176 D - Wizard in Maze(01BFS)
113 0
|
机器学习/深度学习 人工智能 Java
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
102 0
|
机器学习/深度学习
AtCoder Beginner Contest 218 C - Shapes (模拟)
AtCoder Beginner Contest 218 C - Shapes (模拟)
142 0
|
开发者
牛客第六场-Combination of Physics and Maths
题意:选出一个子矩阵,使得所求的压强最大,压强是指这个子矩阵中每个元素之和 / 这个子矩阵最下面一行的元素之和
58 0
牛客第六场-Combination of Physics and Maths
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
94 0
|
Java
HDOJ(HDU) 2164 Rock, Paper, or Scissors?
HDOJ(HDU) 2164 Rock, Paper, or Scissors?
114 0