


S[i] = ‘1’ for each 1 <= ‘i’ <= ‘N’.
1. If the chosen number is 1, then flip all the characters in string.
2. If the chosen number is 2, then flip all the characters at odd indexes.
3. If the chosen number is 3, then flip all the characters at even indexes.
4. If the chosen number is 4, then flip all the characters at (3k + 1) indexes.
1. A binary string is a string in which all characters are either ‘1’ or ‘0’.
2. Flipping a character means that if the character is ‘1’ then change it to 0, or if it is ‘0’ then change it to ‘1’.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains two space-separated integers ‘N’ and ‘M’ denoting the size of string and number of operations.
For each test case, print one integer denoting the number of final strings possible after performing ‘M’ number of operations.
The output of each test case will be printed in a separate line.
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N, M <= 5000
Time Limit: 1 sec
The initial string is ‘111….’ we can do any of the four operations that may result in four different strings, then again we can do any four operations on each of these four strings, which may give some other strings, a key point to observe here is that if we do the same operation 2 times on the original string, then we end up with the original string itself. So doing the same operation even no. of times is the same as not doing that operation at all, and doing the same operation odd no. of times is the same as doing operation 1 time only. Also, we can observe the order of operations does not matter.
For example, let ‘S’ be ‘1001’ performing 1st type operation, and then 2nd type operation will give the string ‘1100’ that is the same as performing 2nd type operation and then 1st type operation. From this, we can say that there are not a very large number of possible final strings. So we can do BFS to perform operations while maintaining a HashSet or unordered_set so that we do not perform operations on the same string twice.
As discussed in the previous approach, there are not many final strings that are possible.
Let's consider all possible cases.
So for ‘N’ > 3, the whole string can be uniquely defined by only the first three characters.
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers