
N = 8, Set of first 8 squares = [1, 4, 9, 16, 25, 36, 49, 64]
Set1 = [1, 16, 36, 49], Set2 = [64, 25, 9, 4]
Here difference is (64 + 25 + 9 + 4) - (1 + 16 + 36 + 49 ) = 0 and = "01101001"
The first line of input contains an integer 'T' denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains an integer 'N'.
For each test case return a binary string of length 'N', if the ‘i’th character of the string is ‘0’ then ‘i’ * ‘i’ is in Set1 else in Set2.
Output for each test case is printed in a separate line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5000
N is always a multiple of 8.
Time Limit: 1 sec
We can observe that,
n^2 - (n+1)^2 - (n+2)^2 +(n+3)^2 -(n+4)^2 +(n+5)^2 +(n+6)^2 -(n+7)^2 = 0
As a result, we will keep taking 8 consecutive numbers from the beginning and split them into two sets. Such that their difference is 0. So in the end, our overall difference will be 0.
The algorithm will be-