forked from Vishal-Aggarwal0305/DSA-CODE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
max_and_value.cpp
54 lines (47 loc) · 1.06 KB
/
max_and_value.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int checkBit(int pattern, int arr[], int n)
{
int count = 0;
cout<<"pattern ="<<pattern<<"\n";
for (int i = 0; i < n; i++)
if ((pattern & arr[i]) == pattern)
count++;
return count;
}
int maxAND (int arr[], int n)
{
int res = 0, count;
for (int bit = 4; bit >= 0; bit--)
{
count = checkBit(res | (1 << bit),arr,n);
cout<<"count ="<<count<<"\n";
if ( count >= 2 )
res |= (1 << bit);
}
cout<<"res ="<<res<<"\n";
return res;
}
int main(){
IOS;
int t;
cin>>t;
while (t--)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<maxAND(a,n);
}
return 0;
}