Code Ensemble: Priya and AND editorial

Here is the solution to the problem Priya and AND:
Python

The Solution in C++

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

int main(){
	int t;
	cin >> t;
	while (t>0){
		int n;
		cin >> n;
		int arr[n];
		for (int i=0;i<n;i++){
			scanf("%d",&arr[i]);
			}
		int c=0;
		for (int i=0;i<n;i++){
			for (int j=0;j<n;j++){
				if (i<j and (arr[i]&arr[j])==arr[i]){
					c++;
					}
				}
			}
		cout << c << "\n";
		t--;
		}
	return 0;
	}
1 Like

It should be

(arr[i] & arr[j]) == arr[i]

'cause & is the bitwise AND, and brackets due to operator precedence of & is lower than ==.

2 Likes

Thanks for letting me know! I’m actually a beginner at C++ so I’m just learning <3

1 Like

Did not knew about the precedence of bitwise and & is less than == . Thanks man

3 Likes