Pascal's Triangle
Time limit2sMemory limit1024 MB
Count how many entries in row n of Pascal's triangle are odd, where n can be as large as 2 billion.
- Level
Easy3 of 10
- Topics
- Math, Bit manipulation, Number theory, Combinatorics
- Solved
- No attempts yet
Problem
Pascal's triangle is an infinite triangle of numbers that looks like this:
The rows of Pascal's triangle are numbered from zero, and the numbers in each row are also numbered from zero. Row zero contains a single number, one, and each subsequent row contains one more number than the previous row. The zeroth and last numbers of each row are one, and each of the others equals the sum of the two numbers above it in the previous row.
Thus row contains numbers. If the -th element of row is denoted , then . This equality also holds for the end elements if the missing elements of the previous row (elements numbered and ) are taken to be zero.
Kolya wants to know how many odd numbers there are in row of Pascal's triangle. He started drawing the triangle, but it soon stopped fitting on the sheet of paper. So Kolya decided to do this with a computer. Help him.
Input
The input file contains the number ().
Output
The output file must contain one number: the count of odd numbers in row of Pascal's triangle.