#P8609. [蓝桥杯 2013 国 A] 约数倍数选卡片

    ID: 7670 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2013数论深度优先搜索 DFS蓝桥杯国赛

[蓝桥杯 2013 国 A] 约数倍数选卡片

Problem Description

In their spare time, Sherlock Holmes and Watson play a game:

There are NN cards with NN 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 66, then the numbers Watson may pick next include:

11, 22, 33, 66, 1212, 1818, 2424 \cdots .

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 1-1.

Input Format

The input has 22 lines. The first line contains several integers separated by spaces (each integer is between 11001 \sim 100), 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