How to solve this question?

Raju and Rani and playing games in the school. Raju has recently learned how to draw angles. He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju.

Input:
First line contains N and K, denoting number of angles Raju knows how to draw and K the number of angles Rani will tell Raju to draw. 
Next line contains, N space separated integers denoting the angles which Raju knows how to draw. Next line contains K space separated numbers denoting the angles Rani wants Raju to draw.

Output:
For each of the K angles Rani wants Raju to draw, output "YES" or "NO" (quotes for clarity) if he can draw those angles or not respectively.

Constraints: 
1 <= N,K <= 10 
0 <= All angles <= 360

Sample Input (Plaintext Link)
1 2
100
60 70
Sample Output (Plaintext Link)
YES
NO
Explanation
Adding 100 fifteen times gives 1500 degrees, which is same as 60.
70 cannot be drawn any way.
Time Limit5 sec(s)
Memory Limit256 MB
Source Limit1024 KB

The solution to the problem is similar to BFS. The solution to the problem goes like this . Initialize the boolean array of angles that can be drawn to false. Make all the angles true in the array which are given to be drawable by Raju. Take a queue of all these angles. Take out one element from the queue. For each element add/subtract all the angles which can be made and set the respective angles true in the array and add them to queue only if new angles in the array are made true. Go on doing till the queue becomes empty. Then check whether k angles given can be made or not from the array.

Note : Everything is done modulo 360. So maximum no of operations are not more than 360.

1 Like

@vermashubhang I appreciate you putting the effort in helping people solve questions but you should discourage Spoon Feeding and encourage people to first present their own solution and logic and give only hints and corrections when necessary.This is clearly some contest question and the user was lazy to put in the effort to solve it and was looking for ready made solutions. If we keep giving direct solutions, then this will just become a forum for solving homework questions for lazy people.

From next time , please dont just post questions but also what you have tried and what is your logic.This forum is for constructive learning not just do people’s homework.

@kcahdog, from next time I will keep that in mind.