Can anyone explain the logic behind the highlighted code

#include<bits/stdc++.h>
using namespace std;

#define loop(i,l,n) for(long i=l;i<n;i++)
#define push_back emplace_back
const int MOD = 1000000007;

template T gcd(T a, T b){return(b?__gcd(a,b):a);}
template T lcm(T a, T b){return(a*(b/gcd(a,b)));}

void run()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("/home/punit/Documents/Cpp Programs/input.txt","r",stdin);
	freopen("/home/punit/Documents/Cpp Programs/output.txt","w",stdout);
#endif

}
int main()
{
run();
int n;
cin>>n;
long arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
long sum = 0;
long bit[32]={0};
int res = 0,count=0;
for(int i=31;i>=0;iā€“)
** {**
** count = 0;**
** for(int j=0;j<n;j++)**
** {**
** int pattern = res|(1<<i);**
** if((arr[j]&pattern)==pattern)**
** {**
** count++;**
** }**
** // cout<<count<<" ";**
** }**
** if(count>=2)**
** {**
** res|=(1<<i);**
** }**
** }**
cout<<res;

}

Some definitions you may find by googling,
#ifndef checks whether the given token has been #defined earlier in the file or in an included file; if not, it includes the code between it and the closing #else or, if no #else is present, #endif statement.
freopen is used to change the I/O stream. For example, when we run the run the program usually input is given through terminal. freopen will change that to input.txt and similarly for output.
As ONLINE_JUDGE has not been defined, freopen will change the I/O.

1 Like