spoj#AND. Magic Bitwise AND Operation
Magic Bitwise AND Operation
Given n integers, your task is to pick k out of them so that the picked number are minimum when do bitwise AND among all of them.
Input
There are multiple test cases for this problem. The first line of the input contains an integer denoting the number of test cases.
For each test case, there are two integers in the first line: n and k, denoting the number of given integers and the number of integers you are asked to pick out. (1<= n <=40, 1<= k <= n)
The second line contains the n integers. You may assume that all integers are smaller than 260.
Note: There are about one thousand randomly generated test cases. Fortunately 90% of them are relatively small.
Output
For each test case, output only one integer - the smallest possible value.
Example
Input: 2 3 2 5 6 7 8 2 238 153 223 247 111 252 253 247</p>Output: Case #1: 4 Case #2: 9