Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem Statement Euler's bloodline has a secret rule that all descendants must choose their favourite number once they turn 1 8 . But if you
Problem Statement
Euler's bloodline has a secret rule that all descendants must choose their favourite number once they turn But if you are a descendant of one the world's greatest Mathermaticians, you are not allowed to choose any random number right?
Aleksandra is turning next month, but the problem is she is very bad at Math. So she approaches you with the conditions to choose a favourite number for her. The secret rule is that the chosen number must be a Parent Mask or Child Mask of at least one of the numbers listed down in a secret scroll passed through generations. Parent Mask of number X is defined as a number that can be obtained by flipping zero or more unset bits of X Similarly Child Mask of X can be obtained by flipping zero or more set bits of X As a reminder, set bits refer to s in the binary representation of the number and unset bits refer to the Os in its binary representation.
For example in binary is a Parent Mask of in binary as we can change the Least Significant bit of from to By similar logic, is a Child Mask of
Written more formally:
Parent MaskX&XX
ChiMask X & X Child MaskX
where & represents bitwise AND operator Note that an integer X is both Parent Mask and Child Mask of itself.
As stated before, Aleksandra is bad at mathematicsher family's genes missed her so she stole the secret scroll with the list of numbers and gave it to you. The scroll contains N numbers Az Az
AN Aleksandra has Q queries, each containing a single integer X Your task is to determine if X can potentially be
Aleksandra's favourite number or not. In short, determine if X is either a Parent Mask or Child Mask of at least one of the numbers A A AN
Input Format:
The first line contains two space separated integers N and Q denoting the count of numbers in the secret scroll and the number of queries Aleksandra has respectively.
Second line contains N space separated integers A A AN the numbers as mentioned in the secret scroll.
The next Q lines each contain a number X which Aleksandra wants to know if it can be her favourite number or not.
Constraints:
N power
Q power
Ai power
X power
Output:
Print "Yes" or Nocase sensitive depending on if X can be Aleksandra's favourite number or not.
Sample input:
Sample output:
Yes
No
Yes
Sample output explanation:
The scroll contains the numbers and here.
The first query, subscrit is a child mask of subacript since subscript in binary is and we can flip the last bit to obtain which is subscipt decimal.
It can similarly be seen that subscript in binary is neither parent mask nor a child mask of both and subscripy
subscript on the other hand is a parent mask of subacriptsubscript
Note that the subscript means binary and subscript mean decimal as usual.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started