Tara recently discovered that each integer can be factored into prime numbers. She first found the process of factoring numbers really exciting, but quickly grew tired of its repetitiveness.
In order to make factoring more challenging, she has decided to limit the factors that she’s allowed to use to of her favourite numbers. She would now like to figure out which numbers are factorable using the numbers. Can you help her out?
Input Specification
The input begins with an integer , the number of factors that Tara is allowed to use.
The second line contains integers , the allowed factors.
The third line contains a single integer , the number of integers to factor.
The fourth line contains integers , the numbers to factor.
For at least 20% of points, each will be prime.
For at least 50% of points, .
Output Specification
For each of the numbers to factor, output a 1
if it is possible to factor the number using the allowed factors, or 0
otherwise. Each number should be considered independently of the rest.
Sample Input 1
4
2 5 6 8
4
10 4 48 15
Sample Output 1
1110
Comments