eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

TianWang`s Game

TianWang`s Game

If you have any idea about WHU ACM Team, you must know our TianWang, and his untouchable gift and ability, especially in game theory. This game problem is from him, too. Scared? Aha, go ahead valorously. Two players are playing this game with \textbf{2·N} integers alternately. In each round, the player can take one integer away, in this way each player has \textbf{N} integers finally. Every two integers have a \textbf{GCD} (\textit{Greatest Common Divisor}), so a player would have integer pairs; the sum of all pairs' \textbf{GCD} is his score. The players' goal is to maximize the value his score subtracts his opponent's. This time, we don't want to know who will win because it's too old; we need the final difference between the two players' score if both of them use the best strategy. \InputFile The first line contains a single integer \textbf{T}, indicating the number of test cases. Each test case begins with one integer \textbf{N}(\textbf{1} ≤ \textbf{N} ≤ \textbf{1000}), indicating there are \textbf{2·N} integers for the players. Then \textbf{2·N} integers \textbf{A_i} (\textbf{1} ≤ \textbf{A_i} ≤ \textbf{1000000}) follow, showing the integers. \OutputFile For each case, output an integer indicating the final difference between the two players' score.
Лимит времени 3 секунды
Лимит использования памяти 64 MiB
Входные данные #1
2
2
2 3 2 3
3
1 2 3 4 5 6
Выходные данные #1
0
1
Источник 2010 Wuhan University 4th "Eming" Cup Programming Contest