-
Notifications
You must be signed in to change notification settings - Fork 118
/
Gould_Sequence.py
33 lines (32 loc) · 1.4 KB
/
Gould_Sequence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
* Gould' Sequence Example
* Row Number Pascal's triangle count of odd numbers in ith row
* 0th row 1 1
* 1st row 1 1 2
* 2nd row 1 2 1 2
* 3rd row 1 3 3 1 4
* 4th row 1 4 6 4 1 2
* 5th row 1 5 10 10 5 1 4
* 6th row 1 6 15 20 15 6 1 4
* 7th row 1 7 21 35 35 21 7 1 8
* 8th row 1 8 28 56 70 56 28 8 1 2
* 9th row 1 9 36 84 126 126 84 36 9 1 4
* 10th row 1 10 45 120 210 256 210 120 45 10 1 4
*
* Code Logic
*
* for row=5
* 5 in binary = 101
* count of 1's =2
* 22= 4
*
* So, 5th row of pascal triangle will have 4 odd number
*/
"""
find_val = int(input("Enter the nth value : "))
ans = find_val
count = 0
while find_val:
count += find_val & 1
find_val >>= 1
print(ans, "th row in pascal Triangle has ", (1 << count), " odd numbers!")