GeeksForGeeks - Company Questions -Handshakes.py

                                 Handshakes

Problem Statement:
We have N persons sitting on a round table. Any person can do a handshake with any other person. In how many ways these N people can make handshakes so that no two handshakes crosses each other. N would be even.


Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N.

Output:
Print number of ways.
Constraints:
1 ≤ T ≤ 20
2 ≤ N ≤ 30

Example:
Input:
2
2
8
Output:
1
14

Solution:
Language: Python

from math import factorial as fact

test_cases = input()
while(test_cases > 0):
    test_cases -= 1
    num = input()/2
    print fact(2*num) / fact(num+1) / fact(num)


Thanks for Visiting, Hope this helps you.... Comments are welcome....

Comments

Popular Posts