|
||||||||||
Magic Bitwise And OperationTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 1839 Accepted Submission(s): 774 Problem Description 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. For example, there are three integers 5, 6 and 7. You are asked to pick two of them. Your possible strategy is (5, 6), (5, 7) or (6, 7). The values when do bitwise and all the picked numbers together are as follows: 5 and 6 = 4 5 and 7 = 5 6 and 7 = 6 The smallest one is 4. 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. n <= 40 The second line contains the n integers. You may assume that all integers are small than 2^60. Notes: 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 is the smallest possible value. Sample Input
Sample Output
Source | ||||||||||
|