[Solution] Twos and Zeros CodeChef Solution
Problem
Kulyash has given you a bag with balls having distinct colours. Among these, balls have the number printed on them and balls have the number printed on them.
He defines the score of a non-empty subset of these balls as:
sum of the balls in size of .
Find the count of non-empty subsets of these balls having their scores divisible by . Since the answer can be huge, output it modulo .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- The first and only line of each test case contains two space-separated integers and — the number balls having and the number of balls having respectively.
Output Format
For each test case, output on a new line, the number of non-empty subsets having scores divisible by , modulo .
Explanation:
Test case : The only non-empty subset having score divisible by is . The score of this subset is , which is divisible by . So, the answer is .
Test case : There are types of subsets having scores divisible by : and . The first type of subset can for formed in ways (there are two s and two s) and the second type can be formed in only way. So, the answer is .
No comments:
Post a Comment