Alan threw a party and invited all her close friend to it. Let us suppose there were 2n…
- User
Alan threw a party and invited all her close friend to it. Let us suppose there were 2n people in the party and all of them were sitting across a round table. The host asked them to shake hands with the condition that no two hands should cross each other i.e if 4 people are sitting then 1st person cannot shake hands with 3rd as that will cross with the hands of 2nd and 4th person. The host wants to know the no of ways in which her friends can shake hands with each other. So your task is to help Alan in finding this. Input First line of input will contain no of test cases t, followed by t lines each containing an integer N(<1000).
Output For each test case, output a single integer which is the no of ways in which persons can shake hands for that particular N. output the answer %100003.
Example Input: 2 2 4 Output: 2 14
Assistant
mod = 100003 max_n = 999 catalan = [0] * (max_n + 1) catalan[0] = 1 for i in range(1, max_n + 1): total = 0 for j in range(i): total += catalan[j] * catalan[i-1 -j] total %= mod catalan[i] = total % mod t = int(input()) for _ in range(t): n = int(input()) print(catalan[n])
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.