• # For Solution

You are given an integer NN. Consider the sequence containing the integers 1,2,,N1,2,…,N in increasing order (each exactly once). Find the length of the longest subarray in this sequence such that the bitwise AND of all elements in the subarray is positive.

### Longest AND Subarray solution codechef

• The first line contains TT denoting the number of test cases. Then the test cases follow.
• Each test case contains a single integer NN on a single line.

### Output Format

For each test case, output on a single line the length of the longest subarray that satisfy the given property.

• 1T1051≤T≤105
• 1N1091≤N≤109

### Longest AND Subarray solution codechef

• Subtask 1 (100 points): Original constraints

### Sample Input 1

5
1
2
3
4
7


Longest AND Subarray solution codechef

1
1
2
2
4


### Longest AND Subarray solution codechef

Test case 11: The only possible subarray we can choose is [1][1].

Test case 22: We can’t take the entire sequence [1,2][1,2] as a subarray because the bitwise AND of 11 and 22 is zero. We can take either [1][1] or [2][2] as a subarray.

Test case 44: It is optimal to take the subarray [2,3][2,3] and the bitwise AND of 22 and 33 is 22.

Test case 55: It is optimal to take the subarray [4,5,6,7][4,5,6,7] and the bitwise AND of all integers in this subarray is 44.