Constructing binary strings
Practice
2.9 (14 votes)
Modular arithmetic
Advanced
Lucas theorem
Algorithms
Mathamatics
Math
Number theory
Problem
35% Success 1709 Attempts 50 Points 1.5s Time Limit 256MB Memory 1024 KB Max Code

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

\(1 \le T \le 10^5\\ 1 \le x, y \le 10^{16}\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
MathematicsHardOpenApprovedLucas's theorem