30 lines
644 B
C++
30 lines
644 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 1000010;
|
|
int a[N];
|
|
int ans;
|
|
|
|
int main() {
|
|
int n;
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++)
|
|
cin >> a[i];
|
|
|
|
set<int> _set; // 哪个数字已经被淘汰掉了
|
|
|
|
for (int i = 30; i >= 0; i--) {
|
|
int cnt = 0; // 枚举每个数字的二进制数位,由高到低
|
|
for (int j = 1; j <= n; j++) {
|
|
if (a[j] >> i & 1 && !_set.count(j))
|
|
cnt++;
|
|
}
|
|
if (cnt >= 2) {
|
|
for (int j = 1; j <= n; j++)
|
|
if (!(a[j] >> i & 1))
|
|
_set.insert(j);
|
|
ans = ans + (1 << i);
|
|
}
|
|
}
|
|
cout << ans << endl;
|
|
return 0;
|
|
} |