#P17189. [ICPC 2017 Hong Kong R] Count the Even Integers

[ICPC 2017 Hong Kong R] Count the Even Integers

Problem Description

Yang Hui’s Triangle is defined as follows.

In the first layer, there are two numbers A1,1A_{1,1} and A1,2A_{1,2} satisfying A1,1=A1,2=1A_{1,1} = A_{1,2} = 1.

Then for each i>1i > 1, the ii-th layer contains i+1i+1 numbers satisfying Ai,1=Ai,i+1=1A_{i,1} = A_{i,i+1} = 1 and Ai,j=Ai1,j1+Ai1,jA_{i,j} = A_{i-1,j-1} + A_{i-1,j} for 1<ji1 < j \le i.

$$\begin{matrix} 1 & 1 \\ 1 & 2 & 1 \\ 1 & 3 & 3 & 1 \\ 1 & 4 & 6 & 4 & 1 \\ 1 & 5 & 10 & 10 & 5 & 1 \\ 1 & 6 & 15 & 20 & 15 & 6 & 1 \\ 1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 \\ 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1 \end{matrix}$$

Now, given an integer NN, you are asked to count the number of even integers in the first NN layers.

Input Format

The input file contains multiple cases, please handle it to the end of file.

For each case, there is only one line containing an integer NN (0<N10500 < N \le 10^{50}).

Output Format

For each case, output the number of the even integers in the first NN layers of Yang Hui’s Triangle.

4
8
12
4
16
42