COWF2 - Editorial

PROBLEM LINK:

Practice
Contest

Author: Sandeep Singh
Tester: Md Shahid
Editorialist: Sandeep Singh

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Xor Operator

PROBLEM:

Given 3 numbers, A, B & C you have to check if the xor of these 3 numbers is divisible by A or B or C.

QUICK EXPLANATION:

Store the xor of A,B & C in Y and check if Y is divisible by A or B or C

EXPLANATION:

This is a very simple problem where you have to just convert the problem statement into a code. We use the xor operator (^) to calculate the xor of A, B & C and then check for its divisibility with A or B or C.
The xor of the numbers is calculated as follows:
Y = A^B^C

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
void solve(){
	int A,B,C,Y;
	cin>>A>>B>>C;
	Y=A^B^C;
	if(Y%A==0||Y%B==0||Y%C==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
		
 
}
int main() {
 
	//freopen("ip6.in", "r", stdin);
	//freopen("op6.out", "w", stdout);
 
	int T ;
	cin>>T;
	while(T--)
		solve();
	return 0;
}
Tester's Solution
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int t;
	cin >> t;
	while(t--) {
		int a, b, c;
		cin >> a >> b >> c;
		int d = a^b^c;
		if(d%a == 0 || d%b == 0 || d%c == 0)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
} 
1 Like