传送门 \looparrowright

Problem Description

Xiao Ming likes counting numbers very much, especially he is fond of counting odd numbers. Maybe he thinks it is the best way to show he is alone without a girl friend. The day 2011.11.11 comes. Seeing classmates walking with their girlfriends, he couldn’t help running into his classroom, and then opened his math book preparing to count odd numbers. He looked at his book, then he found a question : Cn0C_n^0++Cn1C_n^1++Cn2C_n^2+++\cdots+Cnn= ?C_n^n=\ ? Of course, Xiao Ming knew the answer, but he didn’t care about that , What he wanted to know was that how many odd numbers there were? Then he began to count odd numbers. When nn is equal to 11, C10=C11=1C_1^0=C_1^1=1, there are 22 odd numbers. When nn is equal to 22, C20=C22C_2^0=C_2^2==11, there are 22 odd numbers… Suddenly, he found a girl was watching him counting odd numbers. In order to show his gifts on math, he wrote several big numbers what nn would be equal to, but he found it was impossible to finished his tasks, then he sent a piece of information to you, and wanted you a excellent programmer to help him, he really didn’t want to let her down. Can you help him?

Input

Each line contains a integer nn(1n108)(1\le n\le 10^8).

Output

A single line with the number of odd numbers of Cn0C_n^0,,Cn1C_n^1,,Cn2C_n^2,,,\cdots,CnnC_n^n.

Sample Input

1
2
11

Sample Output

2
2
8

Translation

给定正整数 nn,输出 i=0n[Cni1(mod2)]\sum\limits_{i=0}^n \left[C_{n}^i\equiv1\pmod 2\right]

Idea

对于和式的一项 CniC_n^i,设 i,ni,nkk 位二进制数(不会产生溢出),n=nknk1n1n=\overline{n_kn_{k-1}\cdots n_1}i=ikik1i1i=\overline{i_ki_{k-1}\cdots i_1}。根据卢卡斯定理,可将 CniC_n^i 拆解。

$$ \begin{aligned}\begin{pmatrix}n\\i\end{pmatrix}&=\begin{pmatrix}n\bmod 2\\i\bmod 2\end{pmatrix}\times\begin{pmatrix}\left\lfloor\frac{n}{2}\right\rfloor\\\left\lfloor\frac{i}{2}\right\rfloor\end{pmatrix}\\&=\begin{pmatrix}n\bmod 2\\i\bmod 2\end{pmatrix}\times\begin{pmatrix}\left\lfloor\frac{n}{2}\right\rfloor\bmod 2\\\left\lfloor\frac{i}{2}\right\rfloor\bmod 2\end{pmatrix}\times\begin{pmatrix}\left\lfloor\frac{n}{4}\right\rfloor\\\left\lfloor\frac{i}{4}\right\rfloor\end{pmatrix}\\&\quad\quad\quad\quad\quad\quad\quad\quad\quad\vdots\\&=\begin{pmatrix}n_1\\i_1\end{pmatrix}\times\begin{pmatrix}n_2\\i_2\end{pmatrix}\times\cdots\times\begin{pmatrix}n_k\\i_k\end{pmatrix}\\&=\prod\limits_{j=1}^{k}\begin{pmatrix}n_j\\i_j\end{pmatrix}\end{aligned} $$

当且仅当  1jk\forall\ 1\le j\le k,有 $\begin{pmatrix}n_j\\i_j\end{pmatrix}=1$,CniC_n^i 为奇数。遍历 nnkk 个二进制位,若 nj=1n_j=1,那么 ij=0i_j=0ij=1i_j=1,两种选择都满足 $\begin{pmatrix}n_j\\i_j\end{pmatrix}=1$(产生可行的两个分支,数量 ×2\times 2);若 nj=0n_j=0,只有 ij=0i_j=0 满足 $\begin{pmatrix}n_j\\i_j\end{pmatrix}=1$(不产生可行的分支,数量 ×1\times 1)。设 cntcntnn 的二进制中 11 的个数,那么答案为 2cnt2^{cnt}

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<bitset>
#include<cstdio>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
//装入bitset
//调用函数
//bs.count()表示1的数量
bitset<64>bs(n);
printf("%d\n",1<<bs.count());
}
return 0;
}