# Potter and his Magic Wand(CC022)-Editorial

Author : Ivan Ganatra, Ishita Jain
Tester: Ishita Jain
Editorialist: Ivan Ganatra, Ishita Jain

DIFFICULTY : CAKEWALK

PREREQUISITES : Basic observation, Bit manipulation, Bitwise-OR operator.

PROBLEM:
Two decimal numbers are given whose binary representation (each bit will represent one box) will give the current state of torches and wands in each box.
For each box Potter wants to know whether it can emit light or not, representing the status by 1 if it can, or 0 if it can’t.

Print a decimal number representing the final state of each box through its binary form.

QUICK EXPLANATION:
A OR-operation has to be done of both the decimal numbers representing state of torch and magic wand, so that even if one of the bit is 1 from both, final state will be returned as 1.

SOLUTION:
The final state of each box will be represented by 1 if either the torch is on beforehand or the box contains a magic wand. It basically requires doing OR operation of the torch and wand state for each box. 110 will correspond to 6 in decimal representation.

Setter's Solution:
``````#include <bits/stdc++.h>
using namespace std;
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
fast;
long long  t;
cin>>t;
while(t--)
{
long long a,b;
cin>>a>>b;
a=a|b;
cout<<a<<endl;
}
return 0;
}
``````
Tester's Solution:
``````    import java.util.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
sc.nextLine();
while(t>0)
{
t--;
long a = sc.nextLong();
long b = sc.nextLong();
System.out.println(a|b);
}
}
catch(Exception e)
{
}
}
}
``````

Doubts and alternative solutions are welcome.

2 Likes