#P8609. [蓝桥杯 2013 国 A] 约数倍数选卡片
[蓝桥杯 2013 国 A] 约数倍数选卡片
Problem Description
In their spare time, Sherlock Holmes and Watson play a game:
There are cards with integers written on them. The two players take turns removing one card. The rule is that the next player must pick a number that is a divisor or a multiple of the number picked by the previous player. For example, if Holmes removes a card with the number , then the numbers Watson may pick next include:
, , , , , , .
If it is a player's turn and there is no card that satisfies the rule, then that player loses.
Please use a computer to determine, given all the numbers on the remaining cards and the condition of which numbers can be chosen, what choice guarantees a win.
If multiple choices can guarantee a win, output the smallest such number. If you will lose no matter what, output .
Input Format
The input has lines. The first line contains several integers separated by spaces (each integer is between ), representing all cards currently remaining.
The second line also contains several integers separated by spaces, representing the numbers that are allowed to be chosen. Of course, the numbers in the second line must be entirely included among the numbers in the first line.
Output Format
Output the winning move.
2 3 6
3 6
3
1 2 2 3 3 4 5
3 4 5
4
Hint
Time limit: 1 second, 64 MB. Lanqiao Cup 2013, the 4th National Final.
Translated by ChatGPT 5