Constructing binary strings

2.9

14 votes
Modular arithmetic, Advanced, Lucas Theorem, Algorithms, Mathamatics, Math, Number Theory
Problem

Binary strings are the strings whose each character is either ‘0’ or ‘1’.

You are given x numbers of 0s and y numbers of 1s. Your task is to determine the numbers of binary strings that can be formed with x numbers of 0s and y numbers of 1s for which the following function is true. Since, this count can be large, print answers with mod 999983. The definition of the function that is mentioned in the question is as follows:

bool fun(string s){
    one = 0, zero = 0
    for(int i = s.length() - 1; i >= 0; i--){
		if(s[i] is ‘0’):
			zero++
		else:
			one++
		if(zero > one):
			return false
    }
    return true
}

Input format

  • The first line contains a single integer T denoting the number of test case
  • For each test case, a single line contains two integer x and y.

Output format

For each test case, print the number of valid binary strings that can be formed mod 999983.

Constraints

1T1051x,y1016

 

Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

In the first case, valid strings are 00111, 10011, 01011, 10101, 01101.

In the second case, no valid strings are possible.

Editor Image

?